when updating the thanato of the devis, update also the order (canceled or ordered), if the devis is not in order yet, create, wip thanato statistique
This commit is contained in:
parent
ff7cf88bca
commit
9253a69ade
@ -1663,6 +1663,10 @@ class PageController extends Controller {
|
||||
$result = $this->myDb->gestion_update($table, $column, $data, $id, $this->idNextcloud);
|
||||
|
||||
} else {
|
||||
$isUpdateDevisThanato = (strcmp($table, 'devis')== 0) && (strcmp($column, 'id_thanato') ==0);
|
||||
if($isUpdateDevisThanato){
|
||||
$this->orderService->createOrUpdateOrderByDevisAndThanato($id, $data);
|
||||
}
|
||||
$facturecourant = json_decode($this->myDb->getOneFacture($id, $this->idNextcloud))[0];
|
||||
if(strcmp($column, 'date_paiement')==0) {
|
||||
$datecourant = $facturecourant->date_paiement;
|
||||
|
||||
@ -3066,4 +3066,15 @@ class Bdd {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getThanatoByThanatoId($thanatoId){
|
||||
$sql = "SELECT *
|
||||
FROM ".$this->tableprefix."thanato as thanato
|
||||
WHERE thanato.id = ?";
|
||||
$res = $this->execSQLNoJsonReturn($sql,array($thanatoId));
|
||||
if($res){
|
||||
return $res[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -535,10 +535,11 @@ class OrderBdd {
|
||||
orders.fk_provider_id = ? AND
|
||||
MONTH(orders.order_date) = ? AND
|
||||
YEAR(orders.order_date) = ? AND
|
||||
orders.fk_order_type_key = ?
|
||||
orders.fk_order_type_key = ? AND
|
||||
orders.fk_order_status_key != ?
|
||||
ORDER BY orders.order_date ASC;";
|
||||
|
||||
$orders = $this->execSQLNoJsonReturn($sql,[ $providerId,$month,$year,OrderTypeConstant::ORDER_TYPE_PURCHASE]);
|
||||
$orders = $this->execSQLNoJsonReturn($sql,[ $providerId,$month,$year,OrderTypeConstant::ORDER_TYPE_PURCHASE,OrderStatusConstant::CANCELED_KEY]);
|
||||
return $orders;
|
||||
}
|
||||
|
||||
@ -562,4 +563,15 @@ class OrderBdd {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getOrderByDevisId($devisId){
|
||||
$sql = "SELECT * FROM ".$this->orderTablePrefix."orders as orders
|
||||
WHERE orders.fk_devis_id = ? LIMIT 1";
|
||||
|
||||
$result = $this->execSQLNoJsonReturn($sql,[$devisId]);
|
||||
if(!empty($result)){
|
||||
return $result[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -29,7 +29,9 @@ namespace OCA\Gestion\Service\Order;
|
||||
use DateTime;
|
||||
use OCA\Gestion\Constants\BddConstant;
|
||||
use OCA\Gestion\Constants\OrderPdfConstant;
|
||||
use OCA\Gestion\Constants\OrderStatusConstant;
|
||||
use OCA\Gestion\Constants\OrderTypeConstant;
|
||||
use OCA\Gestion\Constants\ThanatoTypeConstant;
|
||||
use OCA\Gestion\Db\Bdd;
|
||||
use OCA\Gestion\Db\OrderBdd;
|
||||
use OCA\Gestion\Helpers\FileExportHelpers;
|
||||
@ -168,4 +170,32 @@ class OrderService {
|
||||
public function addDefaultOrderItem($orderId){
|
||||
$this->orderBdd->addDefaultOrderItem($orderId);
|
||||
}
|
||||
|
||||
public function createOrUpdateOrderByDevisAndThanato($devisId,$thanatoId){
|
||||
$thanato = $this->gestionBdd->getThanatoByThanatoId($thanatoId);
|
||||
if($thanato == null){
|
||||
return null;
|
||||
}
|
||||
$thanatoIsSubContractor = $thanato['fk_thanato_type_key'] == ThanatoTypeConstant::THANATO_TYPE_SUBCONTRACTOR;
|
||||
$devis = $this->gestionBdd->getDevisByDevisId($devisId);
|
||||
if($devis == null){
|
||||
return null;
|
||||
}
|
||||
$devisOrder = $this->orderBdd->getOrderByDevisId($devisId);
|
||||
$thereIsAnOrderRelatedToThisDevis = $devisOrder != null && $devisOrder["fk_order_type_key"] == OrderTypeConstant::ORDER_TYPE_DEVIS;
|
||||
if($thereIsAnOrderRelatedToThisDevis){
|
||||
$orderStatusForUpdate = OrderStatusConstant::ORDERED_KEY;
|
||||
if(!$thanatoIsSubContractor){
|
||||
$orderStatusForUpdate = OrderStatusConstant::CANCELED_KEY;
|
||||
}
|
||||
$this->orderBdd->updateOrderStatus($devisOrder['id'],$orderStatusForUpdate);
|
||||
}
|
||||
else{
|
||||
if($thanatoIsSubContractor){
|
||||
$devisDate = new DateTime($devis['devis_date']);
|
||||
$this->createOrderFromDevisIdAndDate((int)$devisId,$devisDate);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user