-
-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathadd.php
More file actions
executable file
·266 lines (225 loc) · 12.7 KB
/
add.php
File metadata and controls
executable file
·266 lines (225 loc) · 12.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<?php
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
* Copyright (C) DevCode s.r.l.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
include_once __DIR__.'/../../core.php';
use Models\Module;
use Modules\Iva\Aliquota;
$prezzi_ivati = setting('Utilizza prezzi di vendita comprensivi di IVA');
$iva_predefinita = setting('Iva predefinita');
$aliquota_predefinita = floatval(Aliquota::find($iva_predefinita)->percentuale);
?><form action="" method="post" id="add-form">
<input type="hidden" name="op" value="add">
<input type="hidden" name="backto" value="record-edit">
<div class="row">
<div class="col-md-6">
{[ "type": "text", "label": "<?php echo tr('Codice'); ?>", "name": "codice", "required": 0, "value": "<?php echo htmlentities(filter('codice')) ?: ''; ?>", "help": "<?php echo tr('Se non specificato, il codice verrà calcolato automaticamente'); ?>", "validation": "codice" ]}
</div>
<div class="col-md-6">
<span class="pull-right tip text-muted"><input type="checkbox" id="genera_barcode" name="genera_barcode" /> <?php echo tr('Genera automaticamente un barcode'); ?></span>
{[ "type": "text", "label": "<?php echo tr('Barcode'); ?>", "name": "barcode", "required": 0, "value": "<?php echo htmlentities(filter('barcode')) ?: ''; ?>", "validation": "barcode" ]}
</div>
</div>
<div class="row">
<div class="col-md-12">
{[ "type": "textarea", "label": "<?php echo tr('Descrizione'); ?>", "name": "descrizione", "required": 1, "value": "<?php echo htmlentities(filter('descrizione')) ?: ''; ?>", "charcounter": 1 ]}
</div>
<div class="col-md-3">
{[ "type": "select", "label": "<?php echo tr('Categoria'); ?>", "name": "categoria", "required": 0, "ajax-source": "categorie", "icon-after": "add|<?php echo Module::where('name', 'Categorie')->first()->id; ?>" ]}
</div>
<div class="col-md-3">
{[ "type": "select", "label": "<?php echo tr('Sottocategoria'); ?>", "name": "subcategoria", "id": "subcategoria_add", "ajax-source": "sottocategorie", "icon-after": "add|<?php echo Module::where('name', 'Categorie')->first()->id; ?>||hide" ]}
</div>
<div class="col-md-3">
{[ "type": "select", "label": "<?php echo tr('Marca'); ?>", "name": "id_marca", "ajax-source": "marche", "icon-after": "add|<?php echo Module::where('name', 'Marche')->first()->id; ?>" ]}
</div>
<div class="col-md-3">
{[ "type": "select", "label": "<?php echo tr('Modello'); ?>", "name": "id_modello", "id": "id_modello_add", "ajax-source": "modelli", "icon-after": "add|<?php echo Module::where('name', 'Marche')->first()->id; ?>||hide" ]}
</div>
</div>
<div class="card card-info collapsed-card">
<div class="card-header with-border">
<h3 class="card-title"><?php echo tr('Informazioni aggiuntive'); ?></h3>
<div class="card-tools pull-right">
<button type="button" class="btn btn-tool" data-card-widget="collapse">
<i class="fa fa-plus"></i>
</button>
</div>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-4">
{[ "type": "number", "label": "<?php echo tr('Prezzo di acquisto'); ?>", "name": "prezzo_acquisto", "icon-after": "<?php echo currency(); ?>", "value": "<?php echo htmlentities(filter('prezzo_acquisto')) ?: 0; ?>" ]}
</div>
<div class="col-md-4">
{[ "type": "number", "label": "<?php echo tr('Coefficiente di vendita'); ?>", "name": "coefficiente", "help": "<?php echo tr('Imposta un coefficiente per calcolare automaticamente il prezzo di vendita quando cambia il prezzo di acquisto'); ?>." ]}
</div>
<div class="col-md-4">
<?php
if (!setting('Utilizza prezzi di vendita comprensivi di IVA')) {
echo '
<button type="button" class="btn btn-info btn-xs pull-right tip pull-right" title="'.tr('Scorpora l\'IVA dal prezzo di vendita.').'" id="scorpora_iva_add"><i class="fa fa-calculator" aria-hidden="true"></i></button>';
}
?>
{[ "type": "number", "label": "<?php echo tr('Prezzo di vendita'); ?>", "name": "prezzo_vendita", "icon-after": "<?php echo currency(); ?>", "help": "<?php echo setting('Utilizza prezzi di vendita comprensivi di IVA') ? tr('Importo IVA inclusa') : ''; ?>" ]}
</div>
</div>
<div class="row">
<div class="col-md-4">
{[ "type": "number", "label": "<?php echo tr('Quantità iniziale'); ?>", "name": "qta", "decimals": "qta" ]}
</div>
<div class="col-md-4">
{[ "type": "select", "label": "<?php echo tr('Sede'); ?>", "name": "sede", "ajax-source": "sedi_azienda", "value": "0", "required": 1 ]}
</div>
<div class="col-md-4">
{[ "type": "checkbox", "label": "<?php echo tr('Abilita serial number'); ?>", "name": "abilita_serial_add", "help": "<?php echo tr('Abilita serial number in fase di aggiunta articolo in fattura o ddt'); ?>", "value": "<?php echo setting('Serial number abilitato di default'); ?>","placeholder": "<?php echo tr('Serial number'); ?>" ]}
</div>
</div>
<div class="row">
<div class="col-md-4">
{[ "type": "select", "label": "<?php echo tr('Unità di misura'); ?>", "name": "um", "value": "", "ajax-source": "misure", "icon-after": "add|<?php echo Module::where('name', 'Unità di misura')->first()->id; ?>" ]}
</div>
<div class="col-md-4">
{[ "type": "select", "label": "<?php echo tr('U.m. secondaria'); ?>", "name": "um_secondaria", "value": "", "ajax-source": "misure", "help": "<?php echo tr("Unità di misura da utilizzare nelle stampe di Ordini fornitori in relazione all'articolo"); ?>" ]}
</div>
<div class="col-md-4">
{[ "type": "number", "label": "<?php echo tr('Fattore moltiplicativo'); ?>", "name": "fattore_um_secondaria", "value": "", "decimals": "qta", "help": "<?php echo tr("Fattore moltiplicativo per l'unità di misura da utilizzare nelle stampe di Ordini fornitori"); ?>" ]}
</div>
</div>
<div class="row">
<div class="col-md-4">
{[ "type": "select", "label": "<?php echo tr('Conto predefinito di acquisto'); ?>", "name": "idconto_acquisto", "ajax-source": "conti-acquisti" ]}
</div>
<div class="col-md-4">
{[ "type": "select", "label": "<?php echo tr('Conto predefinito di vendita'); ?>", "name": "idconto_vendita", "ajax-source": "conti-vendite" ]}
</div>
<div class="col-md-4">
{[ "type": "select", "label": "<?php echo tr('Iva di vendita'); ?>", "name": "idiva_vendita", "ajax-source": "iva", "valore_predefinito": "Iva predefinita", "help": "<?php echo tr('Se non specificata, verrà utilizzata l\'iva di default delle impostazioni'); ?>" ]}
<input type="hidden" name="prezzi_ivati" value="<?php echo $prezzi_ivati; ?>">
<input type="hidden" name="aliquota_predefinita" value="<?php echo $aliquota_predefinita; ?>">
</div>
</div>
<!--Aggiungo form inserimento ubicazione-->
<div class="row">
<div class="col-md-4">
{[ "type": "select", "label": "<?php echo tr('Ubicazione'); ?>", "name": "ubicazione", "value": "", "ajax-source": "ubicaz" ]}
</div>
</div>
</div>
</div>
<!-- PULSANTI -->
<div class="modal-footer">
<div class="col-md-12 text-right">
<button type="submit" class="btn btn-primary"><i class="fa fa-plus"></i> <?php echo tr('Aggiungi'); ?></button>
</div>
</div>
</form>
<script>
iva_vendita = $("#add-form").find("#idiva_vendita");
percentuale = 0;
$(document).ready(function () {
// Gestione sottocategorie
var sub = $('#add-form').find('#subcategoria_add');
var original = sub.parent().find(".input-group-append button").attr("onclick");
$('#add-form').find('#categoria').change(function() {
updateSelectOption("id_categoria", $(this).val());
session_set('superselect,id_categoria', $(this).val(), 0);
sub.selectReset();
if($(this).val()){
sub.parent().find(".input-group-append button").removeClass("hide");
sub.parent().find(".input-group-append button").attr("onclick", original.replace('&ajax=yes', "&ajax=yes&id_original=" + $(this).val()));
}
else {
sub.parent().find(".input-group-append button").addClass("hide");
}
});
// Gestione modelli
var modello = $('#add-form').find('#id_modello_add');
var originalModello = modello.parent().find(".input-group-append button").attr("onclick");
$('#add-form').find('#id_marca').change(function() {
updateSelectOption("id_marca", $(this).val());
session_set('superselect,id_marca', $(this).val(), 0);
modello.selectReset();
if($(this).val()){
modello.parent().find(".input-group-append button").removeClass("hide");
modello.parent().find(".input-group-append button").attr("onclick", originalModello ? originalModello.replace(/id_original=\d*/, "id_original=" + $(this).val()) : "openModal('<?php echo tr('Aggiungi modello'); ?>', '<?php echo base_path(); ?>/add.php?id_module=<?php echo Module::where('name', 'Marche')->first()->id; ?>&id_original=" + $(this).val() + "')");
}
else {
modello.parent().find(".input-group-append button").addClass("hide");
}
});
input("coefficiente").on('keyup', function(){
if (iva_vendita.val()) {
percentuale = parseFloat(iva_vendita.selectData().percentuale);
}
if (!percentuale) {
percentuale = parseFloat(input("aliquota_predefinita").get());
}
if (input("coefficiente").get()) {
let prezzo_vendita = input('prezzo_acquisto').get() * input("coefficiente").get();
if (parseFloat(input("prezzi_ivati").get())) {
prezzo_vendita = prezzo_vendita + (prezzo_vendita * percentuale / 100);
}
input("prezzo_vendita").set(prezzo_vendita);
input("prezzo_vendita").disable();
$("#scorpora_iva_add").addClass("disabled");
} else {
input("prezzo_vendita").enable();
$("#scorpora_iva_add").removeClass("disabled");
}
});
input("prezzo_acquisto").on('keyup change', function(){
if (iva_vendita.val()) {
percentuale = parseFloat(iva_vendita.selectData().percentuale);
}
if (!percentuale) {
percentuale = parseFloat(input("aliquota_predefinita").get());
}
if (input("coefficiente").get()) {
let prezzo_vendita = input('prezzo_acquisto').get() * input("coefficiente").get();
if (parseFloat(input("prezzi_ivati").get())) {
prezzo_vendita = prezzo_vendita + (prezzo_vendita * percentuale / 100);
}
input("prezzo_vendita").set(prezzo_vendita);
input("prezzo_vendita").disable();
$("#scorpora_iva_add").addClass("disabled");
} else {
input("prezzo_vendita").enable();
$("#scorpora_iva_add").removeClass("disabled");
}
});
$("#scorpora_iva_add").click( function() {
scorpora_iva_add();
});
});
function scorpora_iva_add() {
if (iva_vendita.val()) {
percentuale = parseFloat(iva_vendita.selectData().percentuale);
}
if (!percentuale) {
percentuale = parseFloat(input("aliquota_predefinita").get());
}
if(!percentuale) return;
let input = $("#prezzo_vendita");
let prezzo = input.val().toEnglish();
let scorporato = prezzo * 100 / (100 + percentuale);
input.val(scorporato);
}
$("#genera_barcode").click(function(){
$(".modal #barcode").attr("disabled", $(this).is(":checked")).val("");
});
</script>