|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
$filenameComplete = $this->getFilenameComplete(); |
|
|
$filenameComplete = $this->getFilenameComplete(); |
|
|
|
|
|
|
|
|
if(!file_exists($filenameComplete)) { |
|
|
|
|
|
|
|
|
if (!file_exists($filenameComplete)) { |
|
|
$this->generatePdf(Pdf::DEST_FILE); |
|
|
$this->generatePdf(Pdf::DEST_FILE); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if(file_exists($filenameComplete)) { |
|
|
|
|
|
return Yii::$app->response->sendFile($filenameComplete, $this->getFilename(), ['inline'=>true]); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
throw new ErrorException('File '.$filenameComplete.' not found'); |
|
|
|
|
|
|
|
|
if (file_exists($filenameComplete)) { |
|
|
|
|
|
return Yii::$app->response->sendFile($filenameComplete, $this->getFilename(), ['inline' => true]); |
|
|
|
|
|
} else { |
|
|
|
|
|
throw new ErrorException('File ' . $filenameComplete . ' not found'); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($ordersArray && count($ordersArray)) { |
|
|
if ($ordersArray && count($ordersArray)) { |
|
|
foreach ($ordersArray as $order) { |
|
|
foreach ($ordersArray as $order) { |
|
|
foreach ($order->productOrder as $productOrder) { |
|
|
foreach ($order->productOrder as $productOrder) { |
|
|
$indexProductOrder = $productOrder->product->order; |
|
|
|
|
|
$newProductOrder = clone $productOrder; |
|
|
|
|
|
|
|
|
|
|
|
if (!isset($productsOrdersArray[$indexProductOrder])) { |
|
|
|
|
|
$productsOrdersArray[$indexProductOrder] = [$newProductOrder]; |
|
|
|
|
|
} else { |
|
|
|
|
|
$productOrderMatch = false; |
|
|
|
|
|
foreach ($productsOrdersArray[$indexProductOrder] as &$theProductOrder) { |
|
|
|
|
|
if ($theProductOrder->unit == $productOrder->unit |
|
|
|
|
|
&& ((!$this->isInvoicePrice() && $theProductOrder->price == $productOrder->price) |
|
|
|
|
|
|| ($this->isInvoicePrice() && $theProductOrder->invoice_price == $productOrder->invoice_price) |
|
|
|
|
|
)) { |
|
|
|
|
|
|
|
|
|
|
|
$theProductOrder->quantity += $productOrder->quantity; |
|
|
|
|
|
$productOrderMatch = true; |
|
|
|
|
|
|
|
|
if ($productOrder->product) { |
|
|
|
|
|
$indexProductOrder = $productOrder->product->order; |
|
|
|
|
|
$newProductOrder = clone $productOrder; |
|
|
|
|
|
|
|
|
|
|
|
if (!isset($productsOrdersArray[$indexProductOrder])) { |
|
|
|
|
|
$productsOrdersArray[$indexProductOrder] = [$newProductOrder]; |
|
|
|
|
|
} else { |
|
|
|
|
|
$productOrderMatch = false; |
|
|
|
|
|
foreach ($productsOrdersArray[$indexProductOrder] as &$theProductOrder) { |
|
|
|
|
|
if ($theProductOrder->unit == $productOrder->unit |
|
|
|
|
|
&& ((!$this->isInvoicePrice() && $theProductOrder->price == $productOrder->price) |
|
|
|
|
|
|| ($this->isInvoicePrice() && $theProductOrder->invoice_price == $productOrder->invoice_price) |
|
|
|
|
|
)) { |
|
|
|
|
|
|
|
|
|
|
|
$theProductOrder->quantity += $productOrder->quantity; |
|
|
|
|
|
$productOrderMatch = true; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (!$productOrderMatch) { |
|
|
|
|
|
$productsOrdersArray[$indexProductOrder][] = $newProductOrder; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
if (!$productOrderMatch) { |
|
|
|
|
|
$productsOrdersArray[$indexProductOrder][] = $newProductOrder; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getAliasDirectoryBase() |
|
|
public function getAliasDirectoryBase() |
|
|
{ |
|
|
{ |
|
|
return '@app/web/pdf/'.$this->id_producer.'/'; |
|
|
|
|
|
|
|
|
return '@app/web/pdf/' . $this->id_producer . '/'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function initDirectoryPdf() |
|
|
public function initDirectoryPdf() |
|
|
{ |
|
|
{ |
|
|
$aliasDirectoryBase = $this->getAliasDirectoryBase(); |
|
|
$aliasDirectoryBase = $this->getAliasDirectoryBase(); |
|
|
$directoryPdf = Yii::getAlias($aliasDirectoryBase); |
|
|
$directoryPdf = Yii::getAlias($aliasDirectoryBase); |
|
|
if(!file_exists($directoryPdf)) { |
|
|
|
|
|
|
|
|
if (!file_exists($directoryPdf)) { |
|
|
mkdir($directoryPdf, 0755); |
|
|
mkdir($directoryPdf, 0755); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |