-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3 set new methods for managing item relationship -adding & removing-
inside the core classes.
- Loading branch information
Showing
8 changed files
with
85 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -501,24 +501,23 @@ public function getStatus() | |
/** ** RELATIONSHIPS ** */ | ||
|
||
/** | ||
* addItem | ||
* addNewItem | ||
* adds an item and recalculcates amounts | ||
* it needs to use the 'addNewItem' of the descendant | ||
* it needs to use the 'addItem' of the descendant | ||
* | ||
* @param \Siwapp\CoreBUndle\Entity\AbstractItem $item | ||
* @param \Siwapp\CoreBundle\Entity\AbstractItem $item | ||
* @author JoeZ99 <[email protected]> | ||
*/ | ||
public function addItem(\Siwapp\CoreBundle\Entity\AbstractItem $item) | ||
public function addNewItem(\Siwapp\CoreBundle\Entity\AbstractItem $item) | ||
{ | ||
$this->addNewItem($item);// this method is called from the descendant | ||
$item->setInvoice($this); | ||
$this->addItem($item);// this method is called from the descendant | ||
$item->setParent($this);// this is to ensure relation is established | ||
$this->setAmounts(); | ||
} | ||
|
||
/** | ||
* removeItem | ||
* removes an item and recalculcates amounts | ||
* it needs to use the 'removeThisItem' of the descendant | ||
* | ||
* @param mixed $mixed : can be an integer or an item instance | ||
* - if an integer, removes the item with | ||
|
@@ -528,7 +527,21 @@ public function addItem(\Siwapp\CoreBundle\Entity\AbstractItem $item) | |
*/ | ||
public function removeItem($mixed) | ||
{ | ||
$this->removeThisItem($mixed); | ||
if($mixed instanceof \Siwapp\CoreBundle\Entity\AbstractItem) | ||
{ | ||
foreach($this->getItems() as $ref => $item) | ||
{ | ||
if($item === $mixed) | ||
{ | ||
unset($this->items[$ref]); | ||
break; | ||
} | ||
} | ||
} | ||
else if(is_int($mixed)) | ||
{ | ||
unset($this->items[$mixed]); | ||
} | ||
$this->setAmounts(); | ||
|
||
} | ||
|
@@ -622,24 +635,4 @@ public function preUpdate() | |
// TODO: check for customer matching and update it accordingly. (calling it's updateCustomer method) | ||
} | ||
|
||
/** | ||
* checkStatus is to be implemented by the classes than inherit | ||
* from this | ||
*/ | ||
protected function checkStatus() | ||
{ | ||
} | ||
|
||
/** | ||
* @ORM\PostRemove | ||
*/ | ||
public function postDelete() | ||
{ | ||
foreach($this->items as $it) | ||
{ | ||
$it->delete(); | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,4 +84,19 @@ public function removeTax(\Siwapp\CoreBundle\Entity\Tax $tax) | |
{ | ||
$this->taxes->removeElement($tax); | ||
} | ||
|
||
/** *************** CUSTOM METHODS ************* **/ | ||
|
||
/** *************** RELATIONSHIP METHODS ********* **/ | ||
|
||
/** | ||
* setParent | ||
* | ||
* @param \Siwapp\EstimateBundle\Entity\Estimate $est | ||
* @author JoeZ99 <[email protected]> | ||
*/ | ||
protected function setParent(\Siwapp\EstimateBundle\Entity\Estimate $est) | ||
{ | ||
$this->setEstimate($est); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,4 +87,21 @@ public function removeTax(\Siwapp\CoreBundle\Entity\Tax $tax) | |
{ | ||
$this->taxes->removeElement($tax); | ||
} | ||
|
||
/** ********** CUSTOM METHODS ********* **/ | ||
|
||
/** ********** RELATIONSHIP METHODS *** **/ | ||
|
||
/** | ||
* setParent | ||
* Generic method to set the 'owner' of this item | ||
* it can be either an invoice, recurriong invoice , estimate.. | ||
* | ||
* @param \Siwapp\InvoiceBundle\Entity\Invoice $invoice | ||
* @author JoeZ99 <[email protected]> | ||
*/ | ||
protected function setParent(\Siwapp\InvoiceBundle\Entity\Invoice $invoice) | ||
{ | ||
$this->setInvoice($invoice); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,4 +84,19 @@ public function removeTax(\Siwapp\CoreBundle\Entity\Tax $tax) | |
{ | ||
$this->taxes->removeElement($tax); | ||
} | ||
|
||
/** ************* CUSTOM METHODS ********** **/ | ||
|
||
/** ************* RELATIONSHIP METHODS *********** **/ | ||
|
||
/** | ||
* setParent | ||
* | ||
* @param \Siwapp\RecurringInvoiceBundle\Entity\RecurringInvoice $rinv | ||
* @author JoeZ99 <[email protected]> | ||
*/ | ||
protected function setParent(\Siwapp\RecurringInvoiceBundle\Entity\RecurringInvoice $rinv) | ||
{ | ||
$this->setRecurringInvoice($rinv); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters