|
@@ -0,0 +1,395 @@
|
|
|
+openerp.home_pro_ticket = function (instance, local) {
|
|
|
+ local.widgetInstance = null;
|
|
|
+ local.parentInstance = null;
|
|
|
+
|
|
|
+ local.HomeProTicketWidget = instance.Widget.extend({
|
|
|
+ template : "home_proce_ticket.HomeProTicket",
|
|
|
+
|
|
|
+ init:function(parent){
|
|
|
+ this._super(parent);
|
|
|
+ },
|
|
|
+
|
|
|
+ updateId : function(id){
|
|
|
+ var self = this;
|
|
|
+ self.id=id;
|
|
|
+ },
|
|
|
+
|
|
|
+ start: function () {
|
|
|
+ var self = this;
|
|
|
+ this.$el.click(function (e) {
|
|
|
+ self.fecthInitial();
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ valorNull:function(dato){
|
|
|
+ var valor ="";
|
|
|
+ if (dato){
|
|
|
+ if(dato == true && typeof dato == 'boolean'){
|
|
|
+ valor=" ";
|
|
|
+ }else{
|
|
|
+ valor=dato;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return valor;
|
|
|
+ },
|
|
|
+
|
|
|
+ fecthInitial: function(){
|
|
|
+ var id= openerp.webclient._current_state.id;
|
|
|
+ var self = this;
|
|
|
+ self.fecthAccountInvoice(id).then(function(AccountInvoice){
|
|
|
+ return AccountInvoice;
|
|
|
+ }).then(function(AccountInvoice){
|
|
|
+ self.AccountInvoice = AccountInvoice;
|
|
|
+ return self.fecthAccountInvoiceLine();
|
|
|
+ }).then(function(AccountInvoiceLine){
|
|
|
+ self.AccountInvoiceLine = AccountInvoiceLine;
|
|
|
+ return self.fecthResCurrency();
|
|
|
+ }).then(function(ResCurrency){
|
|
|
+ self.ResCurrency = ResCurrency;
|
|
|
+ return self.drawPDF();
|
|
|
+ });
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+ fecthAccountInvoice: function(id){
|
|
|
+ var self = this;
|
|
|
+ var domain=[['id','=', id]];
|
|
|
+ var AccountInvoice = new instance.web.Model('account.invoice');
|
|
|
+ return AccountInvoice.call('getAccountInvoiceTicket',[domain], {
|
|
|
+ context: new instance.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+ fecthAccountInvoiceLine: function(){
|
|
|
+ var self = this;
|
|
|
+ var invoice_id = _.flatten(_.map(self.AccountInvoice, function (item) {
|
|
|
+ return item.id;
|
|
|
+ }));
|
|
|
+ var domain = [
|
|
|
+ ['invoice_id','=',invoice_id],
|
|
|
+ ];
|
|
|
+ var AccountInvoice = new instance.web.Model('account.invoice.line');
|
|
|
+ return AccountInvoice.call('getAccountInvoiceLineTicket',[domain], {
|
|
|
+ context: new instance.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+ fecthResCurrency: function(){
|
|
|
+ var self = this;
|
|
|
+ var domain = [
|
|
|
+ ['active','=',true],
|
|
|
+ ];
|
|
|
+ var ResCurrency = new instance.web.Model('res.currency');
|
|
|
+ return ResCurrency.call('getResCurrencyTicket',[domain], {
|
|
|
+ context: new instance.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+ getResCurrency: function (id) {
|
|
|
+ var self = this;
|
|
|
+ return _.filter(self.ResCurrency,function (item) {
|
|
|
+ return item.id === id;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ drawPDF:function(){
|
|
|
+ var self = this;
|
|
|
+ var data = [];
|
|
|
+ var info = [];
|
|
|
+ var columns = [];
|
|
|
+ var columns2 = [];
|
|
|
+ var currency = self.getResCurrency(self.AccountInvoice[0].currency_id.id).shift();
|
|
|
+ var pdfDoc = new jsPDF('p', 'mm', [300,76]);
|
|
|
+ _.each(self.AccountInvoiceLine, function(item){
|
|
|
+ data.push({
|
|
|
+ qty: item.quantity,
|
|
|
+ product: item.product_id.name,
|
|
|
+ price_unit: accounting.formatMoney(item.price_unit, '', currency.decimal_places, currency.thousands_separator, currency.decimal_separator),
|
|
|
+ total: accounting.formatMoney(item.quantity * item.price_unit, '', currency.decimal_places, currency.thousands_separator, currency.decimal_separator),
|
|
|
+ amount: item.quantity * item.price_unit,
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ _.each(self.ResCurrency, function(item){
|
|
|
+ info.push({
|
|
|
+ 'description': 'Total en ' + item.local_name + ' =====>',
|
|
|
+ 'amount': accounting.formatMoney(self.AccountInvoice[0].amount_total * ( item.rate_silent / self.AccountInvoice[0].currency_id.rate),'', item.decimal_places, item.thousands_separator, item.decimal_separator),
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ var total_itenes = _.reduce(_.map(data,function(item) {
|
|
|
+ return item.qty;
|
|
|
+ }),function(memo, num) {
|
|
|
+ return memo + num;
|
|
|
+ },0);
|
|
|
+
|
|
|
+ columns.push({
|
|
|
+ title : 'Cant',
|
|
|
+ dataKey: 'qty',
|
|
|
+ align: 'left',
|
|
|
+ });
|
|
|
+
|
|
|
+ columns.push({
|
|
|
+ title : 'Producto',
|
|
|
+ dataKey: 'product',
|
|
|
+ align: 'left',
|
|
|
+ });
|
|
|
+
|
|
|
+ columns.push({
|
|
|
+ title : 'Precio',
|
|
|
+ dataKey: 'price_unit',
|
|
|
+ align: 'right',
|
|
|
+ });
|
|
|
+
|
|
|
+ columns.push({
|
|
|
+ title : 'Total',
|
|
|
+ dataKey: 'total',
|
|
|
+ align: 'right',
|
|
|
+ });
|
|
|
+
|
|
|
+ columns2.push({
|
|
|
+ title : 'valor1',
|
|
|
+ dataKey: 'description',
|
|
|
+ align: 'right',
|
|
|
+ });
|
|
|
+
|
|
|
+ columns2.push({
|
|
|
+ title : 'valor2',
|
|
|
+ dataKey: 'amount',
|
|
|
+ align: 'left',
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ pdfDoc.autoTable(columns, data, {
|
|
|
+ theme: 'grid',
|
|
|
+ styles: {
|
|
|
+ overflow: 'linebreak',
|
|
|
+ columnWidth: 'auto',
|
|
|
+ fontSize: 6,
|
|
|
+ },
|
|
|
+ headerStyles: {
|
|
|
+ fillColor: '#fff',
|
|
|
+ fontSize: 7,
|
|
|
+ textColor:40,
|
|
|
+ },
|
|
|
+ columnStyles: {
|
|
|
+ qty : {columnWidth: 10,halign: 'left'},
|
|
|
+ product : {halign: 'left'},
|
|
|
+ price_unit : {columnWidth: 15,halign: 'right'},
|
|
|
+ total : {columnWidth: 15,halign: 'right'},
|
|
|
+ },
|
|
|
+ margin: { top: 50, horizontal: 5},
|
|
|
+
|
|
|
+ addPageContent: function (data) {
|
|
|
+ /*
|
|
|
+ =====================
|
|
|
+ EMPRESA
|
|
|
+ =====================
|
|
|
+ */
|
|
|
+ pdfDoc.setFontSize(15);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(20,10,self.AccountInvoice[0].company_id.name);
|
|
|
+ /*
|
|
|
+ =====================
|
|
|
+ ESLOGAN
|
|
|
+ =====================
|
|
|
+ */
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(16,14,self.AccountInvoice[0].company_id.rml_header1);
|
|
|
+ /*
|
|
|
+ =====================
|
|
|
+ VENDEDOR
|
|
|
+ =====================
|
|
|
+ */
|
|
|
+ pdfDoc.setFontSize(8);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(2,20,'Vendedor: ');
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(8);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(17,20,self.AccountInvoice[0].user_id.name);
|
|
|
+
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(2,24,'============================================');
|
|
|
+
|
|
|
+ /*
|
|
|
+ =====================
|
|
|
+ NUMERO
|
|
|
+ =====================
|
|
|
+ */
|
|
|
+ pdfDoc.setFontSize(8);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(2,28,'Factura: ');
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(8);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(15,28,self.AccountInvoice[0].number);
|
|
|
+ /*
|
|
|
+ =====================
|
|
|
+ FECHA
|
|
|
+ =====================
|
|
|
+ */
|
|
|
+ pdfDoc.setFontSize(8);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(2,32,'Fecha de Emisión: ');
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(8);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(28,32,moment(self.AccountInvoice[0].date_invoice).format('DD/MM/YYYY'));
|
|
|
+ /*
|
|
|
+ =====================
|
|
|
+ CONDICION
|
|
|
+ =====================
|
|
|
+ */
|
|
|
+ pdfDoc.setFontSize(8);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(2,36,'Condición:');
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(8);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(18,36,'Contado');
|
|
|
+
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(2,40,'============================================');
|
|
|
+
|
|
|
+ /*
|
|
|
+ =====================
|
|
|
+ CLIENTE
|
|
|
+ =====================
|
|
|
+ */
|
|
|
+ pdfDoc.setFontSize(8);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(2,44,'Cliente: ');
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(8);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(15,44,self.AccountInvoice[0].partner_id.name);
|
|
|
+
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(2,48,'============================================');
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ pdfDoc.setFontSize(8);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(2,pdfDoc.autoTable.previous.finalY + 5,'============================================');
|
|
|
+
|
|
|
+ /*
|
|
|
+ =====================
|
|
|
+ ITENES
|
|
|
+ =====================
|
|
|
+ */
|
|
|
+ pdfDoc.setFontSize(8);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(2,pdfDoc.autoTable.previous.finalY + 9,'Total de itenes: ');
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(8);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(25,pdfDoc.autoTable.previous.finalY + 9,accounting.formatNumber(total_itenes,0,'.',','));
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(8);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(2,pdfDoc.autoTable.previous.finalY + 13,'============================================');
|
|
|
+
|
|
|
+ /*
|
|
|
+ =====================
|
|
|
+ SUBTOTAL
|
|
|
+ =====================
|
|
|
+ */
|
|
|
+ pdfDoc.setFontSize(8);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(2,pdfDoc.autoTable.previous.finalY + 17,'Sub-Total: ');
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(8);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(18,pdfDoc.autoTable.previous.finalY + 17, accounting.formatMoney(self.AccountInvoice[0].amount_untaxed, '', currency.decimal_places, currency.thousands_separator, currency.decimal_separator));
|
|
|
+
|
|
|
+ /*
|
|
|
+ =====================
|
|
|
+ IMPUESTOS
|
|
|
+ =====================
|
|
|
+ */
|
|
|
+ pdfDoc.setFontSize(8);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(2,pdfDoc.autoTable.previous.finalY + 21,'Impuestos: ');
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(8);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(20,pdfDoc.autoTable.previous.finalY + 21, accounting.formatMoney(self.AccountInvoice[0].amount_tax, '', currency.decimal_places, currency.thousands_separator, currency.decimal_separator));
|
|
|
+
|
|
|
+ /*
|
|
|
+ =====================
|
|
|
+ IMPUESTOS
|
|
|
+ =====================
|
|
|
+ */
|
|
|
+ pdfDoc.setFontSize(8);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(2,pdfDoc.autoTable.previous.finalY + 25,'Total: ');
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(8);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(13,pdfDoc.autoTable.previous.finalY + 25, accounting.formatMoney(self.AccountInvoice[0].amount_total, '', currency.decimal_places, currency.thousands_separator, currency.decimal_separator));
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(8);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(2,pdfDoc.autoTable.previous.finalY + 29,'============================================');
|
|
|
+
|
|
|
+ pdfDoc.autoTable(columns2, info, {
|
|
|
+ showHeader: 'never',
|
|
|
+ theme: 'plain',
|
|
|
+ styles: {
|
|
|
+ overflow: 'linebreak',
|
|
|
+ columnWidth: 'auto',
|
|
|
+ fontSize: 6,
|
|
|
+ },
|
|
|
+ columnStyles: {
|
|
|
+ description : {halign: 'left'},
|
|
|
+ amount : {columnWidth: 20,halign: 'right'},
|
|
|
+ },
|
|
|
+ startY: pdfDoc.autoTable.previous.finalY + 30,
|
|
|
+ margin: {horizontal: 5},
|
|
|
+ })
|
|
|
+ pdfDoc.setFontSize(8);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(2,pdfDoc.autoTable.previous.finalY + 2,'============================================');
|
|
|
+
|
|
|
+ pdfDoc.save('ticket_' + self.AccountInvoice[0].number + '.pdf');
|
|
|
+ },
|
|
|
+ });
|
|
|
+ if (instance.web && instance.web.FormView) {
|
|
|
+ instance.web.FormView.include({
|
|
|
+ load_form: function (record) {
|
|
|
+ this._super.apply(this, arguments);
|
|
|
+ if (this.model !== 'account.invoice') return;
|
|
|
+ local.parentInstance = this;
|
|
|
+ if (local.widgetInstance) {
|
|
|
+ local.widgetInstance.updateId(record.id);
|
|
|
+ }
|
|
|
+ local.widgetInstance = new local.HomeProTicketWidget(this);
|
|
|
+ var elemento = this.$el.find('.eiru-print-ticket');
|
|
|
+ local.widgetInstance.appendTo(elemento);
|
|
|
+ local.widgetInstance.updateId(record.id);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|