public function saveDebitorAccount($recordData) { $obj = new Billing_Model_DebitorAccount(); $obj->setFromArray($recordData); try { $objId = $obj->getId(); $obj = Billing_Controller_DebitorAccount::getInstance()->get($objId); $obj->setFromArray($recordData); $obj = Billing_Controller_DebitorAccount::getInstance()->update($obj); } catch (Exception $e) { //echo $e->__toString(); $obj = Billing_Controller_DebitorAccount::getInstance()->create($obj); } return $obj->toArray(); }
public function onDonationBooked($donation, $booking, $receipt = null, $openItem = null, $context = 'DONATOR') { $fundMaster = $donation->getForeignRecordBreakNull('fundmaster_id', Donator_Controller_FundMaster::getInstance()); $contact = $fundMaster->getForeignRecordBreakNull('contact_id', Addressbook_Controller_Contact::getInstance()); $debitor = Billing_Controller_Debitor::getInstance()->getByContactOrCreate($contact->getId()); $debitorId = $debitor->getId(); $debitorAccount = new Billing_Model_DebitorAccount(null, true); $debitorAccount->__set('debitor_id', $debitorId); if ($receipt) { $debitorAccount->__set('receipt_id', $receipt->getId()); } if ($openItem) { $debitorAccount->__set('open_item_id', $openItem->getId()); } $value = abs((double) $donation->__get('donation_amount')); $debitorAccount->__set('item_type', 'DEBIT'); if ($donation->__get('is_cancellation')) { $debitorAccount->__set('item_type', 'CREDIT'); $debitorAccount->__set('h_brutto', $value); } else { $debitorAccount->__set('s_brutto', $value); } $prefix = ''; if ($donation->__get('is_cancellation')) { $debitorAccount->__set('item_type', 'CREDIT'); $prefix = 'STORNO '; } $debitorAccount->__set('is_cancelled', $donation->__get('is_cancelled')); $debitorAccount->__set('is_cancellation', $donation->__get('is_cancellation')); $debitorAccount->__set('usage', $prefix . $donation->__get('donation_usage') . ' Sollstellung Spende: Sp.nr ' . $donation->__get('donation_nr') . ' Adress-Nr ' . $contact->getId()); $debitorAccount->__set('debitor_id', $debitorId); $debitorAccount->__set('erp_context_id', $context); $debitorAccount->__set('object_id', $donation->getId()); $debitorAccount->__set('donation_id', $donation->getId()); $date = new Zend_Date($donation->__get('donation_date')); //$date = $date->toString('yyyy-MM-dd'); $debitorAccount->__set('create_date', $date); $debitorAccount->__set('value_date', $date); $debitorAccount->__set('debitor_id', $debitorId); Billing_Controller_DebitorAccount::getInstance()->create($debitorAccount); }