1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Copyright (C) 2017 Joe Nilson <joenilson at gmail.com> |
5
|
|
|
* |
6
|
|
|
* This program is free software: you can redistribute it and/or modify |
7
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
8
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
9
|
|
|
* (at your option) any later version. |
10
|
|
|
* |
11
|
|
|
* This program is distributed in the hope that it will be useful, |
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
* GNU Lesser General Public License for more details. |
15
|
|
|
* |
16
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
17
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
18
|
|
|
*/ |
19
|
|
|
/** |
20
|
|
|
* Description of imprimir_factura_residentes |
21
|
|
|
* |
22
|
|
|
* @author Joe Nilson <joenilson at gmail.com> |
23
|
|
|
*/ |
24
|
|
|
class imprimir_factura_residentes extends fs_controller |
25
|
|
|
{ |
26
|
|
|
public $imprimir; |
27
|
|
|
public $id; |
28
|
|
|
public $factura; |
29
|
|
|
public $factura_logo_uri; |
30
|
|
|
public $facturas_pendientes; |
31
|
|
|
public $cliente; |
32
|
|
|
public $articulo; |
33
|
|
|
public $sizeFactura; |
34
|
|
|
public $total_facturas_pendientes; |
35
|
|
|
|
36
|
|
|
public function __construct() |
37
|
|
|
{ |
38
|
|
|
parent::__construct(__CLASS__, 'Factura Residente', 'ventas', true, false, false); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
protected function private_core() |
42
|
|
|
{ |
43
|
|
|
$this->shared_extensions(); |
44
|
|
|
$id_p = \filter_input(INPUT_POST, 'id'); |
45
|
|
|
$id_g = \filter_input(INPUT_GET, 'id'); |
46
|
|
|
$this->id = ($id_p) ?: $id_g; |
47
|
|
|
$this->facturas_pendientes = array(); |
48
|
|
|
$this->total_facturas_pendientes = 0; |
49
|
|
|
$this->sizeFactura = 100; |
50
|
|
|
|
51
|
|
|
$logo = false; |
52
|
|
|
if (file_exists(FS_MYDOCS.'images/logo.png')) { |
53
|
|
|
$logo = FS_MYDOCS.'images/logo.png'; |
54
|
|
|
} elseif (file_exists(FS_MYDOCS.'images/logo.jpg')) { |
55
|
|
|
$logo = FS_MYDOCS.'images/logo.jpg'; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
if ($logo) { |
59
|
|
|
$type = pathinfo($logo, PATHINFO_EXTENSION); |
60
|
|
|
$data = file_get_contents($logo); |
61
|
|
|
$this->factura_logo_uri = 'data:image/' . $type . ';base64,' . base64_encode($data); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
if ($this->id) { |
65
|
|
|
$this->crearFacturaResidentesStandar(); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
private function crearFacturaResidentesStandar() |
70
|
|
|
{ |
71
|
|
|
$fac = new factura_cliente(); |
72
|
|
|
$this->factura = $fac->get($this->id); |
73
|
|
|
//Agregamos la cantidad de lineas multiplicadas por 4 |
74
|
|
|
$this->sizeFactura+= count($this->factura->get_lineas())*8; |
75
|
|
|
//Agregamos la linea de separación del total |
76
|
|
|
$this->sizeFactura+=4; |
77
|
|
|
//Agregamos las 3 lineas de Neto, FS_IVA y Total |
78
|
|
|
$this->sizeFactura+=12; |
79
|
|
|
//Agregamos un espacio de 4 lineas aprox |
80
|
|
|
$this->sizeFactura+=20; |
81
|
|
|
$cli = new cliente(); |
82
|
|
|
$this->cliente = $cli->get($this->factura->codcliente); |
83
|
|
|
$facturas = $fac->all_from_cliente($this->factura->codcliente); |
84
|
|
|
if ($facturas) { |
85
|
|
|
foreach ($facturas as $f) { |
86
|
|
|
if (!$f->pagada && !$f->anulada) { |
87
|
|
|
$this->facturas_pendientes[] = array( |
88
|
|
|
'factura'=>$f->codigo, |
89
|
|
|
'fecha'=>$f->fecha, |
90
|
|
|
'monto'=>$f->total |
91
|
|
|
); |
92
|
|
|
$this->sizeFactura+=4; |
93
|
|
|
$this->total_facturas_pendientes += $f->total; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
$this->sizeFactura+=20; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function url() |
101
|
|
|
{ |
102
|
|
|
if ($this->id) { |
103
|
|
|
return parent::url().'&id='.$this->id; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function shared_extensions() |
108
|
|
|
{ |
109
|
|
|
$extensiones = array( |
110
|
|
|
array( |
111
|
|
|
'name' => 'factura_residentes', |
112
|
|
|
'page_from' => __CLASS__, |
113
|
|
|
'page_to' => 'ventas_factura', |
114
|
|
|
'type' => 'pdf', |
115
|
|
|
'text' => 'Factura Residentes', |
116
|
|
|
'params' => '' |
117
|
|
|
), |
118
|
|
|
array( |
119
|
|
|
'name' => '001_imprimir_factura_residentes_js', |
120
|
|
|
'page_from' => __CLASS__, |
121
|
|
|
'page_to' => __CLASS__, |
122
|
|
|
'type' => 'head', |
123
|
|
|
'text' => '<script src="' . |
124
|
|
|
FS_PATH . |
|
|
|
|
125
|
|
|
'plugins/residentes/view/js/jspdf.min.js" type="text/javascript"></script>', |
126
|
|
|
'params' => '' |
127
|
|
|
), |
128
|
|
|
array( |
129
|
|
|
'name' => '002_imprimir_factura_residentes_js', |
130
|
|
|
'page_from' => __CLASS__, |
131
|
|
|
'page_to' => __CLASS__, |
132
|
|
|
'type' => 'head', |
133
|
|
|
'text' => '<script src="' . |
134
|
|
|
FS_PATH . |
135
|
|
|
'plugins/residentes/view/js/jsPDF/plugins/split_text_to_size.min.js" ' . |
136
|
|
|
'type="text/javascript"></script>', |
137
|
|
|
'params' => '' |
138
|
|
|
), |
139
|
|
|
); |
140
|
|
|
|
141
|
|
|
foreach ($extensiones as $ext) { |
142
|
|
|
$fsext = new fs_extension($ext); |
143
|
|
|
$fsext->save(); |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|