93 lines
2.3 KiB
PHP
93 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Models\Order;
|
|
use App\Models\OrderLine;
|
|
use App\Models\Customers;
|
|
use App\Models\Timeslot;
|
|
|
|
class CsvOrderWrite extends CsvJobs
|
|
{
|
|
|
|
protected $disk = 'orders';
|
|
|
|
/** @var Order */
|
|
private $order;
|
|
|
|
private $header = [
|
|
"CodeArt",
|
|
"Client livré code",
|
|
"ean13",
|
|
"Type de commande",
|
|
"Unité Elem. Appro",
|
|
"mode de commande",
|
|
"Pcb Art",
|
|
"Date livraison",
|
|
"Qté commandée",
|
|
"Num Cde Client",
|
|
];
|
|
|
|
private $mode_commande = [
|
|
"COLIS" => "UEA",
|
|
"KGM" => "KGM",
|
|
"PCE" => "UB"
|
|
];
|
|
|
|
/**
|
|
* Create a new job instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct(Order $order)
|
|
{
|
|
$this->order = $order;
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function handle()
|
|
{
|
|
/** @var Filesystem */
|
|
$disk = $this->getDisk();
|
|
|
|
/** @var OrderLine */
|
|
$orderlines = $this->order->lines;
|
|
|
|
/** @var Customers */
|
|
$customer = $this->order->customer;
|
|
|
|
/** @var Timeslot */
|
|
$timeslot = $this->order->timeslot;
|
|
|
|
$csvlines[] = $this->header;
|
|
|
|
foreach ($orderlines as $orderline) {
|
|
$product = $orderline->product;
|
|
|
|
$unité_commande = $product->sell_unit ?? 'PCE'; //COLIS, KGM, PCE (faut il introduire un nouveau champs type unité de commande)
|
|
|
|
$oneline = [
|
|
$product->foodProduct->no_art . ".000", //manque le .000 pcb
|
|
$customer->salarie->matricule, //attention matricule a transmettre sans les lettres
|
|
$product->reference,
|
|
"commande ferme",
|
|
$unité_commande,
|
|
$this->mode_commande[$unité_commande], //UEA,KGM,UB (respectivement selon le champ précédent)
|
|
"000", //pcb
|
|
$timeslot->day, //dd/mm/yyyy (attention ça c'est le jour de collecte, peut être qu'il faut livrer un jour avant au point de collecte)
|
|
$orderline->quantity, //
|
|
$this->order->reference,
|
|
];
|
|
|
|
$csvlines[] = $oneline;
|
|
}
|
|
|
|
$data = $this->array2csv($csvlines, ";");
|
|
|
|
$disk->put(date("Ymd_His") . microtime(true) . ".csv", $data);
|
|
}
|
|
}
|