110 lines
2.9 KiB
PHP
110 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use Illuminate\Support\Carbon;
|
|
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;
|
|
|
|
/**
|
|
* en-têtes
|
|
*/
|
|
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",
|
|
];
|
|
|
|
/**
|
|
* correspondance unité d'appro/mode de commande
|
|
*/
|
|
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;
|
|
|
|
//insertion de la ligne d'en-têtes
|
|
$csvlines[] = $this->header;
|
|
|
|
foreach ($orderlines as $orderline) {
|
|
$product = $orderline->product;
|
|
|
|
$unité_commande = $product->order_unit ?? 'PCE'; //COLIS, KGM, PCE (faut il introduire un nouveau champs type unité de commande)
|
|
$code_client = preg_replace('/[^\d]/', '', $customer->salarie->matricule); //matricule rh transmis sans les lettres de l'identifiant windows
|
|
|
|
//convert to date object
|
|
$datLivraison = Carbon::createFromFormat('d/m/Y H:i', $timeslot->day . " " . $timeslot->time);
|
|
|
|
$oneline = [
|
|
$product->foodProduct->no_art, //21/01/2022 : suppression du pcb ici
|
|
$code_client,
|
|
$product->reference,
|
|
"commande ferme",
|
|
$unité_commande,
|
|
$this->mode_commande[$unité_commande], //UEA,KGM,UB (respectivement selon le champ précédent)
|
|
"", //on vide la colonne pcb comme demandé
|
|
$datLivraison->format('d/m/Y'), //dd/mm/yyyy
|
|
$orderline->quantity,
|
|
$this->order->reference,
|
|
];
|
|
|
|
$csvlines[] = $oneline;
|
|
}
|
|
|
|
$data = $this->array2csv($csvlines, ";");
|
|
|
|
//$outputfilename = date("Ymd_His") . microtime(true) . ".csv";
|
|
$outputfilename = "BTQ_" . $this->order->reference . "_" . $code_client . "_" . $customer->salarie->nom . "_" . $customer->salarie->prenom . "_" . str_pad($customer->salarie->code_societe, 3, "0", STR_PAD_LEFT) . ".csv";
|
|
|
|
$disk->put($outputfilename, $data);
|
|
|
|
//send this file by mail
|
|
}
|
|
}
|