matrici sales update
This commit is contained in:
@@ -21,6 +21,9 @@ class MagoMixPurchases
|
||||
/** Sync incrementale: rilegge le fatture degli ultimi N giorni */
|
||||
const SYNC_DAYS = 90;
|
||||
|
||||
/** Fornitori il cui prezzo va verificato (es. conto lavoro: il prezzo non comprende le materie prime) */
|
||||
const CHECK_SUPPLIERS = ['D022' => 'Der-Gom'];
|
||||
|
||||
/** Righe che non sono una mescola da prezzare */
|
||||
const EXCLUDE_RE = '/RECUPER|RITAGLI|\bMIX\b|\bREC\b|DA FILTRARE|RILAVORAR|RESO NON LAVORATO|NON STANDARD|SCADENZA|VARIE|ACCELERANTI|\bPROVA\b/i';
|
||||
|
||||
@@ -149,7 +152,8 @@ class MagoMixPurchases
|
||||
|
||||
/**
|
||||
* €/kg per mescola.
|
||||
* @return array [idmescola => price, last_price, last_date, kg_window, kg_total, old (bool), months [ym => €/kg], suppliers [nome => €/kg]]
|
||||
* @return array [idmescola => price, last_price, last_date, kg_window, kg_total, old (bool), months [ym => €/kg], suppliers [nome => €/kg],
|
||||
* last_supplier, check (nome fornitore da verificare o null)]
|
||||
*/
|
||||
public static function prices(PDO $pdo, int $months = self::PRICE_MONTHS, ?array $lines = null): array
|
||||
{
|
||||
@@ -172,6 +176,8 @@ class MagoMixPurchases
|
||||
if (($a['last_date'] ?? '') <= $l['doc_date']) {
|
||||
$a['last_date'] = $l['doc_date'];
|
||||
$a['last_price'] = $l['value'] / $l['qty'];
|
||||
$a['last_sc'] = (string)$l['supplier_code'];
|
||||
$a['last_sn'] = (string)($l['supplier_name'] ?: $l['supplier_code']);
|
||||
}
|
||||
$ym = substr((string)$l['doc_date'], 0, 7);
|
||||
$a['m'][$ym]['kg'] = ($a['m'][$ym]['kg'] ?? 0) + $l['qty'];
|
||||
@@ -195,11 +201,24 @@ class MagoMixPurchases
|
||||
'old' => !$win,
|
||||
'months' => $ms,
|
||||
'suppliers' => $sup,
|
||||
'last_supplier' => $a['last_sn'],
|
||||
'check' => self::CHECK_SUPPLIERS[$a['last_sc']] ?? null,
|
||||
];
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/** Prezzo di una mescola in un mese: quello del mese, altrimenti l'ultimo dei mesi precedenti */
|
||||
public static function priceAt(array $p, string $ym): ?float
|
||||
{
|
||||
$best = null;
|
||||
foreach ($p['months'] as $m => $v) {
|
||||
if ($m > $ym) break;
|
||||
$best = $v;
|
||||
}
|
||||
return $best;
|
||||
}
|
||||
|
||||
/** Descrizioni d'acquisto non abbinate (o ambigue), raggruppate per parole, ordinate per valore */
|
||||
public static function unmatched(PDO $pdo, ?array $lines = null): array
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user