|
|
@@ -198,63 +198,66 @@ class Subscription extends ActiveRecordCommon |
|
|
|
} |
|
|
|
|
|
|
|
$pointSale = PointSale::findOne($this->id_point_sale); |
|
|
|
$creditFunctioning = $pointSale->getCreditFunctioning(); |
|
|
|
|
|
|
|
$order->auto_payment = 0; |
|
|
|
if ($order->id_user && Producer::getConfig('credit') && $pointSale->credit) { |
|
|
|
if ($creditFunctioning == Producer::CREDIT_FUNCTIONING_OPTIONAL) { |
|
|
|
$order->auto_payment = $this->auto_payment; |
|
|
|
} elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_MANDATORY) { |
|
|
|
$order->auto_payment = 1; |
|
|
|
} elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_USER) { |
|
|
|
$user = User::findOne($order->id_user); |
|
|
|
$userProducer = UserProducer::searchOne([ |
|
|
|
'id_user' => $order->id_user, |
|
|
|
'id_producer' => $distribution->id_producer |
|
|
|
]); |
|
|
|
if ($userProducer) { |
|
|
|
$order->auto_payment = $userProducer->credit_active; |
|
|
|
|
|
|
|
if($pointSale) { |
|
|
|
$creditFunctioning = $pointSale->getCreditFunctioning(); |
|
|
|
|
|
|
|
$order->auto_payment = 0; |
|
|
|
if ($order->id_user && Producer::getConfig('credit') && $pointSale->credit) { |
|
|
|
if ($creditFunctioning == Producer::CREDIT_FUNCTIONING_OPTIONAL) { |
|
|
|
$order->auto_payment = $this->auto_payment; |
|
|
|
} elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_MANDATORY) { |
|
|
|
$order->auto_payment = 1; |
|
|
|
} elseif ($creditFunctioning == Producer::CREDIT_FUNCTIONING_USER) { |
|
|
|
$user = User::findOne($order->id_user); |
|
|
|
$userProducer = UserProducer::searchOne([ |
|
|
|
'id_user' => $order->id_user, |
|
|
|
'id_producer' => $distribution->id_producer |
|
|
|
]); |
|
|
|
if ($userProducer) { |
|
|
|
$order->auto_payment = $userProducer->credit_active; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$order->tiller_synchronization = $order->auto_payment ; |
|
|
|
$order->tiller_synchronization = $order->auto_payment ; |
|
|
|
|
|
|
|
$userPointSale = UserPointSale::searchOne([ |
|
|
|
'id_point_sale' => $this->id_point_sale, |
|
|
|
'id_user' => $this->id_user |
|
|
|
]); |
|
|
|
$userPointSale = UserPointSale::searchOne([ |
|
|
|
'id_point_sale' => $this->id_point_sale, |
|
|
|
'id_user' => $this->id_user |
|
|
|
]); |
|
|
|
|
|
|
|
if ($userPointSale && strlen($userPointSale->comment)) { |
|
|
|
$order->comment_point_sale = $userPointSale->comment; |
|
|
|
} |
|
|
|
if ($userPointSale && strlen($userPointSale->comment)) { |
|
|
|
$order->comment_point_sale = $userPointSale->comment; |
|
|
|
} |
|
|
|
|
|
|
|
$order->save(); |
|
|
|
$order->save(); |
|
|
|
|
|
|
|
// liaison utilisateur / point de vente |
|
|
|
if ($order->id_user) { |
|
|
|
$pointSale = PointSale::findOne($this->id_point_sale); |
|
|
|
$pointSale->linkUser($order->id_user); |
|
|
|
} |
|
|
|
// liaison utilisateur / point de vente |
|
|
|
if ($order->id_user) { |
|
|
|
$pointSale = PointSale::findOne($this->id_point_sale); |
|
|
|
$pointSale->linkUser($order->id_user); |
|
|
|
} |
|
|
|
|
|
|
|
// produits |
|
|
|
$amountTotal = 0; |
|
|
|
$productsAdd = false; |
|
|
|
foreach ($this->productSubscription as $productSubscription) { |
|
|
|
$productOrder = new ProductOrder; |
|
|
|
$productOrder->id_order = $order->id; |
|
|
|
$productOrder->id_product = $productSubscription->product->id; |
|
|
|
$productOrder->quantity = $productSubscription->quantity; |
|
|
|
$productOrder->price = $productSubscription->product->price; |
|
|
|
$productOrder->unit = $productSubscription->product->unit; |
|
|
|
$productOrder->step = $productSubscription->product->step; |
|
|
|
$productOrder->id_tax_rate = $productSubscription->product->taxRate->id; |
|
|
|
$productOrder->save(); |
|
|
|
$productsAdd = true; |
|
|
|
} |
|
|
|
// produits |
|
|
|
$amountTotal = 0; |
|
|
|
$productsAdd = false; |
|
|
|
foreach ($this->productSubscription as $productSubscription) { |
|
|
|
$productOrder = new ProductOrder; |
|
|
|
$productOrder->id_order = $order->id; |
|
|
|
$productOrder->id_product = $productSubscription->product->id; |
|
|
|
$productOrder->quantity = $productSubscription->quantity; |
|
|
|
$productOrder->price = $productSubscription->product->price; |
|
|
|
$productOrder->unit = $productSubscription->product->unit; |
|
|
|
$productOrder->step = $productSubscription->product->step; |
|
|
|
$productOrder->id_tax_rate = $productSubscription->product->taxRate->id; |
|
|
|
$productOrder->save(); |
|
|
|
$productsAdd = true; |
|
|
|
} |
|
|
|
|
|
|
|
if (!$productsAdd) { |
|
|
|
$order->delete(); |
|
|
|
if (!$productsAdd) { |
|
|
|
$order->delete(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |