diff --git a/lib/strategies/BillNumberStrategy.class.php b/lib/strategies/BillNumberStrategy.class.php index 2cd37a7..68660e1 100644 --- a/lib/strategies/BillNumberStrategy.class.php +++ b/lib/strategies/BillNumberStrategy.class.php @@ -78,12 +78,16 @@ protected function generateDefault($bill) { $billCount = $bill->getDocumentService()->createQuery() ->add(Restrictions::ne('publicationstatus', 'DRAFT')) - ->setProjection(Projections::rowCount("billCount")) - ->findColumn("billCount"); + ->add(Restrictions::like('label', '_____', MatchMode::EXACT())) + ->setProjection(Projections::max('label', 'max')) + ->findColumn('max'); return str_pad(strval($billCount[0]+1), 5, '0', STR_PAD_LEFT); } } +/** + * /!\ This strategy is incompatible with immediate order numbering (same numbering format than orders). + */ class order_BillNumberYearSequenceStrategy implements order_BillNumberStrategy { /** @@ -92,18 +96,21 @@ class order_BillNumberYearSequenceStrategy implements order_BillNumberStrategy */ public function generate($bill) { - $year = ($bill->getCreationdate()) ? substr($bill->getCreationdate(), 0, 4) : date("Y"); - $beginDate = date_Converter::convertDateToGMT($year.'-01-01 00:00:00'); - $endDate = date_Converter::convertDateToGMT(($year+1).'-01-01 00:00:00'); - - $billCount = $bill->getDocumentService()->createQuery() - ->setProjection(Projections::rowCount("billCount")) - ->add(Restrictions::ne('publicationstatus', 'DRAFT')) - ->add(Restrictions::ne('id', $bill->getId())) - ->add(Restrictions::ge('transactionDate', $beginDate)) - ->add(Restrictions::lt('transactionDate', $endDate)) - ->findColumn("billCount"); - $newCount = strval($billCount[0]+1); + $row = $bill->getDocumentService()->createQuery() + ->add(Restrictions::ne('publicationstatus', 'DRAFT')) + ->add(Restrictions::ne('id', $bill->getId())) + ->add(Restrictions::like('label', $year.'________', MatchMode::EXACT())) + ->addOrder(Order::desc('label')) + ->setProjection(Projections::property('label')) + ->findUnique(); + if (is_array($row)) + { + $newCount = strval(intval(substr($row['label'], 4))+1); + } + else + { + $newCount = '1'; + } return $year . str_pad($newCount, 8, '0', STR_PAD_LEFT); } } diff --git a/persistentdocument/order.class.php b/persistentdocument/order.class.php index 78b9aab..75af22c 100644 --- a/persistentdocument/order.class.php +++ b/persistentdocument/order.class.php @@ -80,7 +80,7 @@ public function setTaxZone($taxZone) } /** - * @return Array> + * @return array> */ public function getTotalTaxInfoArray() { @@ -99,7 +99,7 @@ public function getTotalTaxInfoArray() /** * @param string $propertyName - * @param Mixed $value serializable data. + * @param mixed $value serializable data. */ public function setGlobalProperty($propertyName, $value) { @@ -108,7 +108,7 @@ public function setGlobalProperty($propertyName, $value) /** * @param string $propertyName - * @return Mixed + * @return mixed */ public function getGlobalProperty($propertyName) { @@ -301,7 +301,7 @@ public function setDiscountDataArray($discountDataArray) { $this->setGlobalProperty('__discount', $discountDataArray); } - + /** * @return boolean */ @@ -410,7 +410,7 @@ public function getTaxRates() { $result = array(); } - return $result; + return $result; } /** @@ -442,7 +442,7 @@ public function setShippingDataArray($shippingArray) } $this->setGlobalProperty('__shipping', $shippingArray); - } + } /** * @param shipping_persistentdocument_mode $shippingMode @@ -455,7 +455,7 @@ public function setShippingModeDocument($shippingMode) $this->setOrderProperty('shippingModeLabel', $shippingMode->getLabel()); $this->setOrderProperty('shippingModeCode', $shippingMode->getCode()); } - else + else { $this->setShippingModeId(null); $this->setOrderProperty('shippingModeLabel', null); @@ -511,7 +511,7 @@ public function getShippingModeLabel() } } } - return implode(', ', $result); + return implode(', ', $result); } /** @@ -576,7 +576,7 @@ public function setBillingModeDocument($billingMode) { $this->setBillingModeId(null); $this->setOrderProperty('paymentConnectorLabel', null); - $this->setOrderProperty('paymentConnectorCode', null); + $this->setOrderProperty('paymentConnectorCode', null); } } @@ -867,5 +867,5 @@ public function getModifierLineArray() public function getTreeNodeLabel() { return $this->getOrderNumber(); - } + } } \ No newline at end of file