|
62 | 62 | <div class="card-body">'; |
63 | 63 |
|
64 | 64 | // Calcolo la quantità dai movimenti in magazzino |
65 | | -$qta_totale = $dbo->fetchOne('SELECT SUM(qta) AS qta FROM mg_movimenti WHERE idarticolo='.prepare($id_record))['qta']; |
66 | | -$qta_totale_attuale = $dbo->fetchOne('SELECT SUM(qta) AS qta FROM mg_movimenti WHERE idarticolo='.prepare($id_record).' AND data <= CURDATE()')['qta']; |
67 | | - |
68 | | -echo ' |
69 | | -<p>'.tr('Quantità calcolata dai movimenti').': <b>'.Translator::numberToLocale($qta_totale, 'qta').' '.$record['um'].'</b> <span class="tip" title="'.tr('Quantità calcolata da tutti i movimenti registrati').'." ><i class="fa fa-question-circle-o"></i></span></p>'; |
70 | | - |
71 | | -echo ' |
72 | | -<p>'.tr('Quantità calcolata attuale').': <b>'.Translator::numberToLocale($qta_totale_attuale, 'qta').' '.$record['um'].'</b> <span class="tip" title="'.tr('Quantità calcolata secondo i movimenti registrati con data oggi o date trascorse').'." ><i class="fa fa-question-circle-o"></i></span></p>'; |
| 65 | +$giacenze = $articolo->getGiacenze(); |
| 66 | +$sedi = $dbo->fetchArray('(SELECT "0" AS id, IF(indirizzo!=\'\', CONCAT_WS(" - ", "'.tr('Sede legale').'", CONCAT(citta, \' (\', indirizzo, \')\')), CONCAT_WS(" - ", "'.tr('Sede legale').'", citta)) AS nomesede FROM an_anagrafiche WHERE idanagrafica = '.prepare(setting('Azienda predefinita')).') UNION (SELECT id, IF(indirizzo!=\'\',CONCAT_WS(" - ", nomesede, CONCAT(citta, \' (\', indirizzo, \')\')), CONCAT_WS(" - ", nomesede, citta )) AS nomesede FROM an_sedi WHERE idanagrafica='.prepare(setting('Azienda predefinita')).')'); |
73 | 67 |
|
74 | 68 | // Individuazione movimenti |
75 | 69 | $movimenti = $articolo->movimentiComposti(); |
76 | 70 |
|
77 | | -$giacenze = $articolo->getGiacenze(); |
78 | | - |
79 | 71 | // Raggruppamento per documento e ordinamento |
80 | 72 | $movimenti = $movimenti->leftJoin('an_sedi', 'mg_movimenti.idsede', 'an_sedi.id') |
81 | 73 | ->orderByDesc('mg_movimenti.data') |
|
89 | 81 | $movimenti = $movimenti->take(20); |
90 | 82 | } |
91 | 83 |
|
92 | | -if (! empty($movimenti)) { |
93 | | - echo ' |
94 | | - <table class="table table-striped table-sm table-bordered"> |
95 | | - <tr> |
96 | | - <th class="text-center" width="40">#</th> |
97 | | - <th class="text-center" width="120">'.tr('Carico').'</th> |
98 | | - <th class="text-center" width="120">'.tr('Scarico').'</th> |
99 | | - <th class="text-center">'.tr('Q.tà progressiva').'</th> |
100 | | - <th>'.tr('Operazione').'</th> |
101 | | - <th>'.tr('Controparte').'</th> |
102 | | - <th class="text-center">'.tr('Sede').'</th> |
103 | | - <th class="text-center" width="120">'.tr('Data').'</th> |
104 | | - <th class="text-center" width="80">#</th> |
105 | | - </tr>'; |
106 | | - |
107 | | - foreach ($movimenti as $i => $movimento) { |
108 | | - // Quantità progressiva |
109 | | - if ($mov[$movimento->idsede]['progressivo_finale'] === null) { |
110 | | - $movimento->progressivo_finale = $giacenze[$movimento->idsede][0]; |
111 | | - } else { |
112 | | - $movimento->progressivo_finale = $mov[$movimento->idsede]['progressivo_iniziale']; |
113 | | - } |
| 84 | +// Raggruppamento movimenti per sede |
| 85 | +$movimenti_per_sede = []; |
| 86 | +foreach ($movimenti as $movimento) { |
| 87 | + $idsede = (int) $movimento->idsede; |
| 88 | + $movimenti_per_sede[$idsede][] = $movimento; |
| 89 | +} |
114 | 90 |
|
115 | | - $movimento->progressivo_iniziale = $movimento->progressivo_finale - $movimento->qta; |
| 91 | +if (!empty($movimenti)) { |
| 92 | + foreach ($sedi as $sede) { |
| 93 | + $movimenti_sede = $movimenti_per_sede[(int) $sede['id']] ?? []; |
116 | 94 |
|
117 | | - $mov[$movimento->idsede]['progressivo_iniziale'] = $movimento->progressivo_iniziale; |
118 | | - $mov[$movimento->idsede]['progressivo_finale'] = $movimento->progressivo_finale; |
| 95 | + if (empty($movimenti_sede)) { |
| 96 | + continue; |
| 97 | + } |
119 | 98 |
|
120 | | - // Quantità |
121 | | - echo ' |
122 | | - <tr> |
123 | | - <td class="text-center"> |
124 | | - '.count($movimenti) - $i.' |
125 | | - </td> |
126 | | - <td class="text-center" style="color: green;"> |
127 | | - '.($movimento->qta > 0 ? numberFormat($movimento->qta, 'qta').' '.$record['um'] : '').' |
128 | | - </td> |
129 | | - <td class="text-center" style="color: red;"> |
130 | | - '.($movimento->qta < 0 ? numberFormat(abs($movimento->qta), 'qta').' '.$record['um'] : '').' |
131 | | - </td> |
132 | | - <td class="text-center"> |
133 | | - '.numberFormat($movimento->progressivo_iniziale, 'qta').' '.$record['um'].' |
134 | | - <i class="fa fa-arrow-circle-right"></i> |
135 | | - '.numberFormat($movimento->progressivo_finale, 'qta').' '.$record['um'].' |
136 | | - </td> |
137 | | - <td> |
138 | | - '.$movimento->descrizione.''.($movimento->hasDocument() ? ' - '.reference($movimento->getDocument()) : '').' |
139 | | - </td> |
140 | | - <td> |
141 | | - '.Anagrafica::find($movimento->getDocument()->idanagrafica)->ragione_sociale.' |
142 | | - </td> |
143 | | - <td class="text-center"> |
144 | | - '.($movimento->nomesede ?: tr('Sede legale')).' |
145 | | - </td>'; |
146 | | - |
147 | | - // Data |
148 | | - $utente = $dbo->table('zz_users')->where('id', $movimento->idutente)->first(); |
149 | | - $data = ($movimento->data ?: $movimento->data_movimento); |
150 | 99 | echo ' |
151 | | - <td class="text-center">'.dateFormat($data).' <span class="tip" title="'.tr('Creazione movimento: _DATE_ <br>Creatore movimento: _USER_', [ |
152 | | - '_DATE_' => timestampFormat($movimento->data_movimento), |
153 | | - '_USER_' => $utente->username, |
154 | | - ]).'"><i class="fa fa-question-circle-o"></i></span> </td>'; |
| 100 | + <div class="card"> |
| 101 | + <div class="card-header"> |
| 102 | + <h3 class="card-title">'.$sede['nomesede'].'</h3> |
| 103 | + </div> |
| 104 | + <div class="card-body"> |
| 105 | + <table class="table table-striped table-sm table-bordered"> |
| 106 | + <tr> |
| 107 | + <th class="text-center" width="40">#</th> |
| 108 | + <th class="text-center" width="120">'.tr('Carico').'</th> |
| 109 | + <th class="text-center" width="120">'.tr('Scarico').'</th> |
| 110 | + <th class="text-center">'.tr('Q.tà progressiva').'</th> |
| 111 | + <th>'.tr('Operazione').'</th> |
| 112 | + <th>'.tr('Controparte').'</th> |
| 113 | + <th class="text-center" width="120">'.tr('Data').'</th> |
| 114 | + <th class="text-center" width="80">#</th> |
| 115 | + </tr>'; |
| 116 | + |
| 117 | + foreach ($movimenti_sede as $i => $movimento) { |
| 118 | + // Quantità progressiva |
| 119 | + if ($mov[$movimento->idsede]['progressivo_finale'] === null) { |
| 120 | + $movimento->progressivo_finale = $giacenze[$movimento->idsede][0]; |
| 121 | + } else { |
| 122 | + $movimento->progressivo_finale = $mov[$movimento->idsede]['progressivo_iniziale']; |
| 123 | + } |
| 124 | + |
| 125 | + $movimento->progressivo_iniziale = $movimento->progressivo_finale - $movimento->qta; |
| 126 | + |
| 127 | + $mov[$movimento->idsede]['progressivo_iniziale'] = $movimento->progressivo_iniziale; |
| 128 | + $mov[$movimento->idsede]['progressivo_finale'] = $movimento->progressivo_finale; |
| 129 | + |
| 130 | + // Quantità |
| 131 | + echo ' |
| 132 | + <tr> |
| 133 | + <td class="text-center"> |
| 134 | + '.count($movimenti_sede) - $i.' |
| 135 | + </td> |
| 136 | + <td class="text-center" style="color: green;"> |
| 137 | + '.($movimento->qta > 0 ? numberFormat($movimento->qta, 'qta').' '.$record['um'] : '').' |
| 138 | + </td> |
| 139 | + <td class="text-center" style="color: red;"> |
| 140 | + '.($movimento->qta < 0 ? numberFormat(abs($movimento->qta), 'qta').' '.$record['um'] : '').' |
| 141 | + </td> |
| 142 | + <td class="text-center"> |
| 143 | + '.numberFormat($movimento->progressivo_iniziale, 'qta').' '.$record['um'].' |
| 144 | + <i class="fa fa-arrow-circle-right"></i> |
| 145 | + '.numberFormat($movimento->progressivo_finale, 'qta').' '.$record['um'].' |
| 146 | + </td> |
| 147 | + <td> |
| 148 | + '.$movimento->descrizione.''.($movimento->hasDocument() ? ' - '.reference($movimento->getDocument()) : '').' |
| 149 | + </td> |
| 150 | + <td> |
| 151 | + '.Anagrafica::find($movimento->getDocument()->idanagrafica)->ragione_sociale.' |
| 152 | + </td>'; |
| 153 | + |
| 154 | + // Data |
| 155 | + $utente = $dbo->table('zz_users')->where('id', $movimento->idutente)->first(); |
| 156 | + $data = ($movimento->data ?: $movimento->data_movimento); |
| 157 | + echo ' |
| 158 | + <td class="text-center">'.dateFormat($data).' <span class="tip" title="'.tr('Creazione movimento: _DATE_ <br>Creatore movimento: _USER_', [ |
| 159 | + '_DATE_' => timestampFormat($movimento->data_movimento), |
| 160 | + '_USER_' => $utente->username, |
| 161 | + ]).'"><i class="fa fa-question-circle-o"></i></span> </td>'; |
155 | 162 |
|
156 | | - // Operazioni |
157 | | - echo ' |
158 | | - <td class="text-center">'; |
| 163 | + // Operazioni |
| 164 | + echo ' |
| 165 | + <td class="text-center">'; |
| 166 | + |
| 167 | + if (AuthOSM::admin() && $movimento->isManuale()) { |
| 168 | + echo ' |
| 169 | + <a class="btn btn-danger btn-xs ask" data-backto="record-edit" data-op="delmovimento" data-idmovimento="'.$movimento->tipo_gruppo.'"> |
| 170 | + <i class="fa fa-trash"></i> |
| 171 | + </a>'; |
| 172 | + } |
159 | 173 |
|
160 | | - if (AuthOSM::admin() && $movimento->isManuale()) { |
161 | 174 | echo ' |
162 | | - <a class="btn btn-danger btn-xs ask" data-backto="record-edit" data-op="delmovimento" data-idmovimento="'.$movimento->tipo_gruppo.'"> |
163 | | - <i class="fa fa-trash"></i> |
164 | | - </a>'; |
| 175 | + </td> |
| 176 | + </tr>'; |
165 | 177 | } |
166 | 178 |
|
167 | 179 | echo ' |
168 | | - </td> |
169 | | - </tr>'; |
| 180 | + </table> |
| 181 | + </div> |
| 182 | + </div>'; |
170 | 183 | } |
171 | | - |
172 | | - echo ' |
173 | | - </table>'; |
174 | 184 | } else { |
175 | 185 | echo ' |
176 | 186 | <div class="alert alert-info"> |
|
0 commit comments