|
@@ -0,0 +1,387 @@
|
|
|
+openerp.pagare_decorart = function (instance, local) {
|
|
|
+ local.widgetInstance = null;
|
|
|
+ local.parentInstance = null;
|
|
|
+
|
|
|
+ local.PagareDecorartWidget = instance.Widget.extend({
|
|
|
+ template : "pagare_decorart.PagareDecorart",
|
|
|
+ jsonDoc:[],
|
|
|
+
|
|
|
+ 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.fetchAccountInvoice(id).then(function(AccountInvoice){
|
|
|
+ return AccountInvoice;
|
|
|
+ }).then(function(AccountInvoice){
|
|
|
+ self.AccountInvoice = AccountInvoice;
|
|
|
+ return self.fetchAccountInvoiceQuota(id);
|
|
|
+ }).then(function(AccountInvoiceQuota){
|
|
|
+ self.AccountInvoiceQuota = AccountInvoiceQuota;
|
|
|
+ return self.fetchAccountInvoiceLine();
|
|
|
+ }).then(function(AccountInvoiceLine){
|
|
|
+ self.AccountInvoiceLine = AccountInvoiceLine;
|
|
|
+ return self.drawPDF();
|
|
|
+ });
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchAccountInvoice: function(id){
|
|
|
+ var domain=[['id','=', id]];
|
|
|
+ var AccountInvoice = new instance.web.Model('account.invoice');
|
|
|
+ return AccountInvoice.call('getAccountInvoicePagare',[domain], {
|
|
|
+ context: new instance.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchAccountInvoiceQuota: function(id){
|
|
|
+ var domain=[['id','=', id]];
|
|
|
+ var AccountInvoice = new instance.web.Model('account.invoice');
|
|
|
+ return AccountInvoice.call('getAccountInvoicePagareQuota',[domain], {
|
|
|
+ context: new instance.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ fetchAccountInvoiceLine: function () {
|
|
|
+ var self = this;
|
|
|
+ var invoice_ids = _.flatten(_.map(self.AccountInvoice,function(map){
|
|
|
+ return map.id;
|
|
|
+ }));
|
|
|
+ var domain=[['invoice_id','in',invoice_ids]];
|
|
|
+ var AccountInvoiceLine = new instance.web.Model('account.invoice.line');
|
|
|
+ return AccountInvoiceLine.call('getAccountInvoiceLinePagare',[domain], {
|
|
|
+ context: new instance.web.CompoundContext()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ drawPDF:function(){
|
|
|
+ var self = this;
|
|
|
+ var AccountInvoice = self.AccountInvoice;
|
|
|
+ var CurrencyBase = self.AccountInvoice[0].currency_id[0];
|
|
|
+ var docItem = [];
|
|
|
+ var docQuotaItem = [];
|
|
|
+ var getColumns = [];
|
|
|
+ var getColumnsQuota = [];
|
|
|
+
|
|
|
+ var pdfDoc = new jsPDF("p","mm","a4");
|
|
|
+ pdfDoc.addImage("data:image/png;base64," + AccountInvoice[0].company_id[0].logo, 'PNG',10,10,20,15);
|
|
|
+
|
|
|
+ _.each(self.AccountInvoiceLine, function(item){
|
|
|
+ docItem.push({
|
|
|
+ name : item.name,
|
|
|
+ quantity : item.quantity,
|
|
|
+ price_unit : accounting.formatMoney(item.price_unit,'',CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ price_subtotal : accounting.formatMoney(item.price_subtotal,'',CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ });
|
|
|
+ });
|
|
|
+ getColumns.push({
|
|
|
+ title : 'Descripción',
|
|
|
+ dataKey: 'name'
|
|
|
+ });
|
|
|
+ getColumns.push({
|
|
|
+ title : 'Cantidad',
|
|
|
+ dataKey: 'quantity'
|
|
|
+ });
|
|
|
+ getColumns.push({
|
|
|
+ title : 'Precio Unitario',
|
|
|
+ dataKey: 'price_unit'
|
|
|
+ });
|
|
|
+ getColumns.push({
|
|
|
+ title : 'subtotal',
|
|
|
+ dataKey: 'price_subtotal'
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ pdfDoc.autoTable(getColumns, docItem, {
|
|
|
+ theme: 'grid',
|
|
|
+ styles: {
|
|
|
+ overflow: 'linebreak',
|
|
|
+ columnWidth: 'auto',
|
|
|
+ fontSize: 7
|
|
|
+ },
|
|
|
+ headerStyles: {
|
|
|
+ textColor: 20,
|
|
|
+ fillColor: null,
|
|
|
+ lineWidth: 0.1,
|
|
|
+ fontSize: 9
|
|
|
+ },
|
|
|
+ columnStyles: {
|
|
|
+ name : {columnWidth: 'auto'},
|
|
|
+ quantity : {columnWidth: 30, halign:'right'},
|
|
|
+ price_unit : {columnWidth: 30, halign:'right'},
|
|
|
+ price_subtotal : {columnWidth: 30, halign:'right'},
|
|
|
+ },
|
|
|
+
|
|
|
+ margin: { top: 80, horizontal: 10},
|
|
|
+
|
|
|
+ addPageContent: function (data) {
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(11);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(20);
|
|
|
+ pdfDoc.text(40, 13,'Empresa: ');
|
|
|
+ pdfDoc.setFontSize(11);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.text(60, 13, 'DECORART');
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(11);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(20);
|
|
|
+ pdfDoc.text(120, 13,'Número de Operación: ');
|
|
|
+ pdfDoc.setFontSize(11);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.text(165, 13, AccountInvoice[0].origin);
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(11);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(20);
|
|
|
+ pdfDoc.text(120, 18,'Número de Documento: ');
|
|
|
+ pdfDoc.setFontSize(11);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.text(165, 18, AccountInvoice[0].number);
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(11);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(20);
|
|
|
+ pdfDoc.text(120, 23,'Responsable: ');
|
|
|
+ pdfDoc.setFontSize(11);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.text(147, 23, AccountInvoice[0].user_name);
|
|
|
+
|
|
|
+ // Cuadro principal
|
|
|
+ pdfDoc.rect(10, 30, pdfDoc.internal.pageSize.getWidth() - 20 , 40, 'S');
|
|
|
+ // Cuadro fecha de emision
|
|
|
+ pdfDoc.rect(10, 30, 80, 10, 'S');
|
|
|
+ pdfDoc.setFontSize(8);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.setTextColor(20);
|
|
|
+ pdfDoc.text(12, 36,'Fecha de emisión: ');
|
|
|
+ pdfDoc.text(45, 36, moment(AccountInvoice[0].date_invoice).format('DD/MM/YYYY'));
|
|
|
+ // RUC / Documento de identidad No.
|
|
|
+ pdfDoc.rect(10, 40, pdfDoc.internal.pageSize.getWidth() - 20, 10, 'S');
|
|
|
+ pdfDoc.text(12, 46,'RUC / Documento de Identidad No.: ' + AccountInvoice[0].partner_id[0].ruc);
|
|
|
+ // Nombre o Razon Social
|
|
|
+ pdfDoc.rect(10, 50, pdfDoc.internal.pageSize.getWidth() - 20, 10, 'S');
|
|
|
+ pdfDoc.text(12, 56,'Nombre o Razón Social: ' + AccountInvoice[0].partner_id[0].name);
|
|
|
+ // Telefono
|
|
|
+ pdfDoc.rect(10, 60, 95, 10, 'S');
|
|
|
+ pdfDoc.text(12, 66,'Teléfono: ' + self.valorNull(AccountInvoice[0].partner_id[0].phone));
|
|
|
+
|
|
|
+ // Dirreccion
|
|
|
+ pdfDoc.rect(105, 60, 95, 10, 'S');
|
|
|
+ pdfDoc.text(107, 66,'Direccion: ' + self.valorNull(AccountInvoice[0].partner_id[0].address));
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ _.each(self.AccountInvoiceQuota, function(item){
|
|
|
+ docQuotaItem.push({
|
|
|
+ date : moment(item.date).format('DD/MM/YYYY'),
|
|
|
+ name : item.name,
|
|
|
+ amount : accounting.formatMoney(item.amount,'',CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
|
|
|
+ });
|
|
|
+ });
|
|
|
+ getColumnsQuota.push({
|
|
|
+ title : 'Fecha',
|
|
|
+ dataKey: 'date'
|
|
|
+ });
|
|
|
+ getColumnsQuota.push({
|
|
|
+ title : 'Descripción',
|
|
|
+ dataKey: 'name'
|
|
|
+ });
|
|
|
+ getColumnsQuota.push({
|
|
|
+ title : 'Valor de la Cuota',
|
|
|
+ dataKey: 'amount'
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ var finalY = pdfDoc.autoTable.previous.finalY;
|
|
|
+ pdfDoc.autoTable(getColumnsQuota, docQuotaItem, {
|
|
|
+ theme: 'grid',
|
|
|
+ startY: finalY + 20,
|
|
|
+ styles: {
|
|
|
+ overflow: 'linebreak',
|
|
|
+ columnWidth: 'auto',
|
|
|
+ fontSize: 7,
|
|
|
+
|
|
|
+ },
|
|
|
+ headerStyles: {
|
|
|
+ textColor: 20,
|
|
|
+ fillColor: null,
|
|
|
+ lineWidth: 0.1,
|
|
|
+ fontSize: 9
|
|
|
+ },
|
|
|
+ columnStyles: {
|
|
|
+ date : {columnWidth: 'auto', halign: 'center'},
|
|
|
+ name : {columnWidth: 'auto', halign: 'center'},
|
|
|
+ amount : {columnWidth: 'auto', halign: 'right'}
|
|
|
+ },
|
|
|
+ margin: {horizontal: 10},
|
|
|
+ addPageContent: function (data) {
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(85,finalY + 15,'Información de Cuotas ');
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(10,finalY + 5,'Total: ' + accounting.formatMoney(AccountInvoice[0].amount_total,CurrencyBase.symbol,CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator));
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ pdfDoc.addPage();
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ i=0
|
|
|
+ _.each(self.AccountInvoiceQuota, function(item){
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(14);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.text(80,15+i,'DECORART');
|
|
|
+ pdfDoc.setFontSize(12);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.rect(10, 18+i, 95, 0, 'S');
|
|
|
+ pdfDoc.text(12,23+i,'Número de Operación:' + AccountInvoice[0].origin);
|
|
|
+ pdfDoc.setFontSize(12);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.rect(105, 18+i, 95, 0, 'S');
|
|
|
+ pdfDoc.text(110,23+i,'Fecha de Operación: ' + moment(AccountInvoice[0].date_invoice).format('DD/MM/YYYY'));
|
|
|
+ pdfDoc.setFontSize(12);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.text(12,28+i,'C.I. N°: ' + self.valorNull(AccountInvoice[0].partner_id[0].ruc));
|
|
|
+ pdfDoc.setFontSize(12);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.text(110,28+i,'Vendedor: ' + self.valorNull(AccountInvoice[0].user_name));
|
|
|
+ pdfDoc.setFontSize(12);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.text(12,33+i,'Cliente: ' + self.valorNull(AccountInvoice[0].partner_id[0].name));
|
|
|
+ pdfDoc.rect(10, 35+i, 95, 0, 'S');
|
|
|
+ pdfDoc.setFontSize(12);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.text(12,43+i,'Cuota N°:' + item.name);
|
|
|
+ pdfDoc.rect(105, 35+i, 95, 0, 'S');
|
|
|
+ pdfDoc.setFontSize(12);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.text(110,43+i,'Vence: ' + moment(item.date).format('DD/MM/YYYY'));
|
|
|
+ pdfDoc.setFontSize(12);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.text(12,49+i,'Monto Cuota:' + item.amount);
|
|
|
+ pdfDoc.setFontSize(12);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.text(110,56+i,'Firma: _ _ _ _ _ _ _ _ _');
|
|
|
+ i=i+55
|
|
|
+ if (i>220) {
|
|
|
+ pdfDoc.addPage();
|
|
|
+ i=0
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ pdfDoc.addPage();
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(16);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(80,25,'PAGARE A LA ORDEN');
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.rect(10, 45, 95, 7, 'S');
|
|
|
+ pdfDoc.text(12,50,'Número de Operación: ' + AccountInvoice[0].origin);
|
|
|
+ pdfDoc.rect(105, 45, 95, 7, 'S');
|
|
|
+ pdfDoc.text(110,50,'Fecha de Operación: ' + moment(AccountInvoice[0].date_invoice).format('DD/MM/YYYY'));
|
|
|
+ pdfDoc.rect(10, 55, 95, 7, 'S');
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.text(12,60,'Monto a pagar: ' + accounting.formatMoney(AccountInvoice[0].amount_total,CurrencyBase.symbol,CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator));
|
|
|
+ pdfDoc.rect(105, 55, 95, 7, 'S');
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ _.each(self.AccountInvoiceQuota, function(item){
|
|
|
+ varfecha=item.date;
|
|
|
+ });
|
|
|
+ pdfDoc.text(110,60,'Vencimiento: ' + moment(varfecha).format('DD/MM/YYYY'));
|
|
|
+ var total_in_letters = instance.web.num2word(AccountInvoice[0].amount_total);
|
|
|
+ pdfDoc.setFontSize(12);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.text(12,70,'Pagaré a la orden de ' + AccountInvoice[0].company_id[0].name + '.');
|
|
|
+ pdfDoc.setFontSize(12);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.text(12,75,'La suma de Guaraníes: ' + total_in_letters);
|
|
|
+ pdfDoc.rect(10, 80, pdfDoc.internal.pageSize.getWidth() - 15 , 60,'S');
|
|
|
+ pdfDoc.setFontSize(12);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ var paragraph="Queda expresamente convenido que la falta de pago de este pagaré me (nos) constituirá en mora automáticamente, sin necesidad de interpelación judicial o extrajudicial alguna, devengando durante el tiempo de la mora un interés del ....%, un interés moratorio del ....% y una comisión del ....% por el simple retardo sin que esto implique prórroga del plazo de la obligación. Asimismo me (nos) obligamos a pagar cualquier gasto en que incurra el acreedor con relación a este préstamo, en caso de que el mismo sea reclamado por la vía judicial o extrajudicial. El simple vencimiento establecerá mora, autorizando la inclusión de nombre personal o Razón Social que represento, a la base de datos de Informconf, conforme a lo establecido en la Ley 168/01, como también para que se pueda proveer la información a terceros interesados. A los efectos legales y procesales nos sometemos a la jurisdicción de los Tribunales de Ciudad del Este y renunciando a cualquier otra que pudiera corresponder las partes constituyen domicilio real y especial en los lugares señalados en el presente documento.";
|
|
|
+ pdfDoc.text(paragraph,12,85,{maxWidth:188,align:'justify'});
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(10);
|
|
|
+ pdfDoc.setFontStyle('bold');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(10,165,'DEUDOR');
|
|
|
+ pdfDoc.text(110,165,'CO-DEUDOR');
|
|
|
+
|
|
|
+ pdfDoc.setFontSize(9);
|
|
|
+ pdfDoc.setFontStyle('normal');
|
|
|
+ pdfDoc.setTextColor(40);
|
|
|
+ pdfDoc.text(10,175,'Nombre y Apellido: ' + AccountInvoice[0].partner_id[0].name);
|
|
|
+ pdfDoc.text(110,175,'Nombre y Apellido:');
|
|
|
+ pdfDoc.text(10,180,'RUC / DNI: ' + self.valorNull(AccountInvoice[0].partner_id[0].ruc));
|
|
|
+ pdfDoc.text(110,180,'RUC / DNI:');
|
|
|
+ pdfDoc.text(10,185,'Domicilio: ' + self.valorNull(AccountInvoice[0].partner_id[0].address));
|
|
|
+ pdfDoc.text(110,185,'Domicilio:');
|
|
|
+ pdfDoc.text(10,195,'Telefono: ' + self.valorNull(AccountInvoice[0].partner_id[0].phone));
|
|
|
+ pdfDoc.text(110,195,'Telefono:');
|
|
|
+ pdfDoc.text(10,200,'Celular: ' + self.valorNull(AccountInvoice[0].partner_id[0].mobile));
|
|
|
+ pdfDoc.text(110,200,'Celular:');
|
|
|
+ pdfDoc.text(10,210,'Firma: ');
|
|
|
+ pdfDoc.text(110,210,'Firma:');
|
|
|
+
|
|
|
+ pdfDoc.save('pagare.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.PagareDecorartWidget(this);
|
|
|
+ var elemento = this.$el.find('.oe_form').find('.pagare_button_box');
|
|
|
+ local.widgetInstance.appendTo(elemento);
|
|
|
+ local.widgetInstance.updateId(record.id);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+};
|