mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-23 23:07:46 +01:00
Aggiunta sconti combinati nei listini
This commit is contained in:
parent
0c89c7b10b
commit
476aacb6ac
@ -20,6 +20,10 @@ function start_inputmask(element) {
|
||||
regex: "[A-Za-z0-9#_|\/\\-.]*",
|
||||
}).addClass('bound');
|
||||
|
||||
$(element + '.math-mask').not('.bound').inputmask('Regex', {
|
||||
regex: "[0-9,.+\-]*",
|
||||
}).addClass('bound');
|
||||
|
||||
if (globals.is_mobile) {
|
||||
$(element + '.inputmask-decimal, ' + element + '.date-mask, ' + element + '.timestamp-mask').each(function () {
|
||||
$(this).attr('type', 'tel');
|
||||
|
@ -30,6 +30,7 @@ return [
|
||||
'modules/stati_contratto' => 'Modules\StatiContratto',
|
||||
'modules/tipi_intervento' => 'Modules\TipiIntervento',
|
||||
'modules/categorie_documenti' => 'Modules\CategorieDocumentali',
|
||||
'modules/listini' => 'Modules\Listini',
|
||||
'plugins/exportFE' => 'Plugins\ExportFE',
|
||||
'plugins/importFE' => 'Plugins\ImportFE',
|
||||
'plugins/receiptFE' => 'Plugins\ReceiptFE',
|
||||
|
@ -2,40 +2,35 @@
|
||||
|
||||
include_once __DIR__.'/../../core.php';
|
||||
|
||||
use Modules\Listini\Listino;
|
||||
|
||||
switch (post('op')) {
|
||||
case 'update':
|
||||
$nome = post('nome');
|
||||
$prc_guadagno = post('prc_guadagno');
|
||||
$note = post('note');
|
||||
$listino->nome = post('nome');
|
||||
$listino->note = post('note');
|
||||
|
||||
if (abs($prc_guadagno) > 100) {
|
||||
$prc_guadagno = ($prc_guadagno > 0) ? 100 : -100;
|
||||
}
|
||||
$listino->percentuale = post('prc_guadagno');
|
||||
$listino->percentuale_combinato = post('prc_combinato');
|
||||
|
||||
$query = 'UPDATE mg_listini SET nome='.prepare($nome).', prc_guadagno='.prepare($prc_guadagno).', note='.prepare($note).' WHERE id='.prepare($id_record);
|
||||
$dbo->query($query);
|
||||
$listino->save();
|
||||
|
||||
flash()->info(tr('Informazioni salvate correttamente!'));
|
||||
break;
|
||||
|
||||
case 'add':
|
||||
$nome = post('nome');
|
||||
$prc_guadagno = post('prc_guadagno');
|
||||
$listino = Listino::build(post('nome'), post('prc_guadagno'));
|
||||
|
||||
if (abs($prc_guadagno) > 100) {
|
||||
$prc_guadagno = ($prc_guadagno > 0) ? 100 : -100;
|
||||
}
|
||||
$listino->percentuale_combinato = post('prc_combinato');
|
||||
|
||||
if (isset($nome)) {
|
||||
$dbo->query('INSERT INTO mg_listini( nome, prc_guadagno ) VALUES ('.prepare($nome).', '.prepare($prc_guadagno).')');
|
||||
$id_record = $dbo->lastInsertedID();
|
||||
$listino->save();
|
||||
$id_record = $listino->id;
|
||||
|
||||
flash()->info(tr('Nuovo listino aggiunto!'));
|
||||
}
|
||||
flash()->info(tr('Nuovo listino aggiunto!'));
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
$dbo->query('DELETE FROM mg_listini WHERE id='.prepare($id_record));
|
||||
$listino->delete();
|
||||
|
||||
flash()->info(tr('Listino eliminato!'));
|
||||
break;
|
||||
}
|
||||
|
@ -7,11 +7,15 @@ include_once __DIR__.'/../../core.php';
|
||||
<input type="hidden" name="backto" value="record-edit">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="col-md-4">
|
||||
{[ "type": "text", "label": "<?php echo tr('Nome'); ?>", "name": "nome", "required": 1 ]}
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<div class="col-md-4">
|
||||
{[ "type": "text", "label": "<?php echo tr('Rincaro/sconto combinato'); ?>", "name": "prc_combinato", "value": "$prc_combinato$", "icon-after": "%", "class": "math-mask text-right", "help": "<?php echo tr('Esempio: 50+10-20 viene convertito in 50% di sconto con 10% aggiuntivo sul totale scontato e 20% di maggiorazione sul totale finale (54% di sconto finale)').'. '.tr('Sono ammessi i segni +/-').'.'; ?>" ]}
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
{[ "type": "number", "label": "<?php echo tr('Rincaro/sconto'); ?>", "name": "prc_guadagno", "required": 1, "value": "0", "icon-after": "%", "help": "<?php echo tr('Il valore positivo indica uno sconto: per applicare una percentuale di rincaro inserire un valore negativo'); ?>" ]}
|
||||
</div>
|
||||
</div>
|
||||
@ -23,3 +27,26 @@ include_once __DIR__.'/../../core.php';
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
$("#prc_guadagno").change(function () {
|
||||
if ($(this).val() && $(this).val() != (0).toLocale()) {
|
||||
$("#prc_combinato").attr("disabled", true).addClass("disabled");
|
||||
} else {
|
||||
$("#prc_combinato").attr("disabled", false).removeClass("disabled");
|
||||
}
|
||||
});
|
||||
|
||||
$("#prc_combinato").change(function () {
|
||||
if ($(this).val()) {
|
||||
$("#prc_guadagno").attr("disabled", true).addClass("disabled").attr("required", false);
|
||||
} else {
|
||||
$("#prc_guadagno").attr("disabled", false).removeClass("disabled").attr("required", true);
|
||||
}
|
||||
});
|
||||
|
||||
$(document).ready(function () {
|
||||
$("#prc_combinato").change();
|
||||
$("#prc_guadagno").change();
|
||||
})
|
||||
</script>
|
||||
|
@ -14,12 +14,16 @@ include_once __DIR__.'/../../core.php';
|
||||
|
||||
<div class="panel-body">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="col-md-4">
|
||||
{[ "type": "text", "label": "<?php echo tr('Nome'); ?>", "name": "nome", "required": 1, "value": "$nome$" ]}
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
{[ "type": "number", "label": "<?php echo tr('Rincaro/sconto'); ?>", "name": "prc_guadagno", "required": 1, "value": "$prc_guadagno$", "icon-after": "%", "help": "<?php echo tr('Il valore positivo indica uno sconto').'. '.tr('Per applicare una percentuale di rincaro inserire un valore negativo').'.'; ?>" ]}
|
||||
<div class="col-md-4">
|
||||
{[ "type": "text", "label": "<?php echo tr('Rincaro/sconto combinato'); ?>", "name": "prc_combinato", "value": "$prc_combinato$", "icon-after": "%", "class": "math-mask text-right", "help": "<?php echo tr('Esempio: 50+10-20 viene convertito in 50% di sconto con 10% aggiuntivo sul totale scontato e 20% di maggiorazione sul totale finale (54% di sconto finale)').'. '.tr('Sono ammessi i segni +/-').'.'; ?>", "disabled": "<?php echo intval(empty($record['prc_combinato']) && !empty($record['prc_guadagno'])); ?>" ]}
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
{[ "type": "number", "label": "<?php echo tr('Rincaro/sconto'); ?>", "name": "prc_guadagno", "required": 1, "value": "$prc_guadagno$", "icon-after": "%", "help": "<?php echo tr('Il valore positivo indica uno sconto').'. '.tr('Per applicare una percentuale di rincaro inserire un valore negativo').'.'; ?>", "disabled": "<?php echo intval(!empty($record['prc_combinato'])); ?>" ]}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -37,3 +41,21 @@ include_once __DIR__.'/../../core.php';
|
||||
<a class="btn btn-danger ask" data-backto="record-list">
|
||||
<i class="fa fa-trash"></i> <?php echo tr('Elimina'); ?>
|
||||
</a>
|
||||
|
||||
<script>
|
||||
$("#prc_guadagno").change(function () {
|
||||
if ($(this).val() && $(this).val() != (0).toLocale()) {
|
||||
$("#prc_combinato").attr("disabled", true).addClass("disabled");
|
||||
} else {
|
||||
$("#prc_combinato").attr("disabled", false).removeClass("disabled");
|
||||
}
|
||||
});
|
||||
|
||||
$("#prc_combinato").change(function () {
|
||||
if ($(this).val()) {
|
||||
$("#prc_guadagno").attr("disabled", true).addClass("disabled").attr("required", false);
|
||||
} else {
|
||||
$("#prc_guadagno").attr("disabled", false).removeClass("disabled").attr("required", true);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
@ -2,6 +2,10 @@
|
||||
|
||||
include_once __DIR__.'/../../core.php';
|
||||
|
||||
use Modules\Listini\Listino;
|
||||
|
||||
if (isset($id_record)) {
|
||||
$record = $dbo->fetchOne('SELECT * FROM mg_listini WHERE id='.prepare($id_record));
|
||||
|
||||
$listino = Listino::find($id_record);
|
||||
}
|
||||
|
70
modules/listini/src/Listino.php
Normal file
70
modules/listini/src/Listino.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Listini;
|
||||
|
||||
use Common\Model;
|
||||
|
||||
class Listino extends Model
|
||||
{
|
||||
protected $table = 'mg_listini';
|
||||
|
||||
public static function build($nome, $percentuale)
|
||||
{
|
||||
$model = parent::build();
|
||||
|
||||
$model->nome = $nome;
|
||||
$model->percentuale = $percentuale;
|
||||
$model->save();
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function setPercentualeCombinatoAttribute($value)
|
||||
{
|
||||
$this->prc_combinato = $value;
|
||||
}
|
||||
|
||||
public function getPercentualeCombinatoAttribute()
|
||||
{
|
||||
return $this->prc_combinato;
|
||||
}
|
||||
|
||||
public function setPercentualeAttribute($value)
|
||||
{
|
||||
$value = floatval($value);
|
||||
if (abs($value) > 100) {
|
||||
$value = ($value > 0) ? 100 : -100;
|
||||
}
|
||||
|
||||
$this->prc_guadagno = $value;
|
||||
}
|
||||
|
||||
public function getPercentualeAttribute()
|
||||
{
|
||||
return $this->prc_guadagno;
|
||||
}
|
||||
|
||||
public function save(array $options = [])
|
||||
{
|
||||
$combinato = $this->prc_combinato;
|
||||
if (!empty($combinato)) {
|
||||
$sign = substr($combinato, 0, 1);
|
||||
$original = $sign != '+' && $sign != '-' ? '+'.$combinato : $combinato;
|
||||
$pieces = preg_split('/[+,-]+/', $original);
|
||||
unset($pieces[0]);
|
||||
|
||||
$result = 1;
|
||||
$text = $original;
|
||||
foreach ($pieces as $piece) {
|
||||
$sign = substr($text, 0, 1);
|
||||
$text = substr($text, 1 + strlen($piece));
|
||||
|
||||
$result *= 1 - floatval($sign.$piece) / 100;
|
||||
}
|
||||
|
||||
$this->percentuale = $result;
|
||||
}
|
||||
|
||||
return parent::save($options);
|
||||
}
|
||||
}
|
@ -4,9 +4,9 @@ namespace Modules\Utenti\API\v1;
|
||||
|
||||
use API\Interfaces\CreateInterface;
|
||||
use API\Resource;
|
||||
use API\Response;
|
||||
use Auth;
|
||||
use Update;
|
||||
use API\Response;
|
||||
|
||||
class Login extends Resource implements CreateInterface
|
||||
{
|
||||
|
@ -850,3 +850,6 @@ ALTER TABLE `or_righe_ordini` CHANGE `qta_evasa` `qta_evasa` decimal(12, 6) NOT
|
||||
|
||||
UPDATE `zz_settings` SET `tipo` = 'list[1,2,3,4,5]' WHERE `nome` = 'Cifre decimali per importi';
|
||||
UPDATE `zz_settings` SET `tipo` = 'list[1,2,3,4,5]' WHERE `nome` = 'Cifre decimali per quantità';
|
||||
|
||||
-- Aggiunta percentuale combinata in listini
|
||||
ALTER TABLE `mg_listini` ADD `prc_combinato` VARCHAR(255);
|
||||
|
Loading…
x
Reference in New Issue
Block a user