|
857 | 857 | flash()->warning(tr('Nessuna aliquota IVA modificata!')); |
858 | 858 | } |
859 | 859 |
|
| 860 | + break; |
| 861 | + |
| 862 | + case 'add_ddt_rientrato': |
| 863 | + $class = post('class'); |
| 864 | + $id_documento = post('id_documento'); |
| 865 | + |
| 866 | + // Individuazione del documento originale |
| 867 | + if (!is_subclass_of($class, Common\Document::class)) { |
| 868 | + return; |
| 869 | + } |
| 870 | + $documento = $class::find($id_documento); |
| 871 | + |
| 872 | + $tipo = Tipo::where('dir', '!=', $documento->direzione)->first(); |
| 873 | + $stato = Stato::where('name', 'Evaso')->first()->id; |
| 874 | + |
| 875 | + // Duplicazione documento |
| 876 | + $id_segment = post('id_segment'); |
| 877 | + if (get('id_segment')) { |
| 878 | + $id_segment = get('id_segment'); |
| 879 | + } |
| 880 | + |
| 881 | + if (post('create_document') == 'on') { |
| 882 | + $ddt = DDT::build($documento->anagrafica, $tipo, $documento->data, $id_segment); |
| 883 | + $ddt->stato()->associate($stato); |
| 884 | + $ddt->idcausalet = post('id_causale_trasporto'); |
| 885 | + $ddt->idpagamento = $documento->idpagamento; |
| 886 | + $ddt->idsede_partenza = $documento->idsede_destinazione; |
| 887 | + $ddt->idsede_destinazione = $documento->idsede_partenza; |
| 888 | + $ddt->save(); |
| 889 | + |
| 890 | + $id_record = $ddt->id; |
| 891 | + } |
| 892 | + |
| 893 | + $evadi_qta_parent = true; |
| 894 | + $righe = $documento->getRighe(); |
| 895 | + foreach ($righe as $riga) { |
| 896 | + if (post('evadere')[$riga->id] == 'on' and !empty(post('qta_da_evadere')[$riga->id])) { |
| 897 | + $qta = post('qta_da_evadere')[$riga->id]; |
| 898 | + |
| 899 | + $copia = $riga->copiaIn($ddt, $qta, $evadi_qta_parent); |
| 900 | + $id_iva = ($ddt->anagrafica->idiva_acquisti ?: setting('Iva predefinita')); |
| 901 | + $copia->setPrezzoUnitario(0, $id_iva); |
| 902 | + |
| 903 | + // Aggiornamento seriali dalla riga dell'ordine |
| 904 | + if ($copia->isArticolo()) { |
| 905 | + $serials = is_array(post('serial')[$riga->id]) ? post('serial')[$riga->id] : []; |
| 906 | + $copia->serials = $serials; |
| 907 | + } |
| 908 | + |
| 909 | + $copia->save(); |
| 910 | + } |
| 911 | + } |
| 912 | + |
| 913 | + // Modifica finale dello stato |
| 914 | + if (post('create_document') == 'on') { |
| 915 | + $ddt->idstatoddt = post('id_stato'); |
| 916 | + $ddt->save(); |
| 917 | + } |
| 918 | + |
| 919 | + ricalcola_costiagg_ddt($id_record); |
| 920 | + |
| 921 | + // Messaggio informativo |
| 922 | + $message = tr('_DOC_ aggiunto!', [ |
| 923 | + '_DOC_' => $ddt->getReference(), |
| 924 | + ]); |
| 925 | + flash()->info($message); |
| 926 | + |
860 | 927 | break; |
861 | 928 | } |
0 commit comments