protected function appendDependentRecords($record) { if ($record->__get('article_id')) { $article = Billing_Controller_Article::getInstance()->get($record->__get('article_id')); $record->__set('article_id', $article); //$this->appendForeignRecordToRecord($record, 'article_id', 'article_id', 'id', new Billing_Backend_Article()); } if ($record->__get('stock_location_id')) { $this->appendForeignRecordToRecord($record, 'stock_location_id', 'stock_location_id', 'id', new Billing_Backend_StockLocation()); } }
protected function appendDependentRecords($record) { if ($record->__get('order_template_id')) { $this->appendForeignRecordToRecord($record, 'order_template_id', 'order_template_id', 'id', new Billing_Backend_OrderTemplate()); } if ($record->__get('article_id')) { $article = Billing_Controller_Article::getInstance()->get($record->__get('article_id')); $record->__set('article_id', $article); } if ($record->__get('vat_id')) { $this->appendForeignRecordToRecord($record, 'vat_id', 'vat_id', 'id', new Billing_Backend_Vat()); } if ($record->__get('price_group_id')) { $this->appendForeignRecordToRecord($record, 'price_group_id', 'price_group_id', 'id', new Billing_Backend_PriceGroup()); } if ($record->__get('unit_id')) { $this->appendForeignRecordToRecord($record, 'unit_id', 'unit_id', 'id', new Billing_Backend_ArticleUnit()); } }
/** * * Create new receipt position based on an article object * @param {Billing_Model_Article} $article */ public function getPositionFromArticle($article, $debitor, $amount) { $article = Billing_Controller_Article::getInstance()->get($article->getId()); $articleId = $article->__get('id'); $priceGroupId = $debitor->__get('price_group_id'); $receiptPosition = $this->getEmptyOrderTemplatePosition(); // add data to receipt position $receiptPosition->__set('article_id', $articleId); $receiptPosition->__set('price_group_id', $priceGroupId); $receiptPosition->__set('vat_id', $article->__get('vat_id')); $receiptPosition->__set('name', $article->__get('name')); $receiptPosition->__set('description', $article->__get('description')); $debPrice = $article->getPriceForDebitor($debitor); $priceNetto = $debPrice['price_netto']; $receiptPosition->__set('price_netto', $priceNetto); $receiptPosition->__set('amount', $amount); $receiptPosition->__set('unit_id', $article->__get('article_unit_id')->id); // calculate the position $this->calculate($receiptPosition); $receiptPosition->__set('vat_id', $article->__get('vat_id')->id); return $receiptPosition; }
public function getArticleNumbers() { try { $aArticleNumbers = Billing_Controller_Article::getInstance()->getArticleNumbers(); return array('success' => true, 'data' => $aArticleNumbers); } catch (Exception $e) { return array('success' => false, 'data' => null, 'errorInfo' => $e->__toString()); } }
private function inspectAddOrderPosition($receipt, $oPosition) { // if its an invoice -> decrease stock amount if ($receipt->isInvoice() || $receipt->isCredit()) { $stfController = Billing_Controller_StockFlow::getInstance(); $sf = new Billing_Model_StockFlow(null, true); $stockLocation = Billing_Controller_StockLocation::getInstance()->getDefaultStockLocation(); $stockLocationId = $stockLocation->getId(); $article = $oPosition->getForeignRecord('article_id', Billing_Controller_Article::getInstance()); if ($article->__get('is_stock_article')) { $articleId = $article->getId(); $priceNetto = $oPosition->__get('price_netto'); $direction = 'OUT'; $bookingDate = strftime('%Y-%m-%d'); $amount = $oPosition->__get('amount'); $reason = 'Lieferung'; $sf->__set('article_id', $articleId); $sf->__set('stock_location_id', $stockLocationId); $sf->__set('price_netto', $priceNetto); $sf->__set('direction', $direction); $sf->__set('booking_date', $bookingDate); $sf->__set('amount', $amount); $sf->__set('reason', $reason); $stfController->create($sf); } } }
/** * * get donation_amount sums collected by campaigns */ public function getCreateDonationData() { try { if (!class_exists('Donator_Model_Donation')) { return null; } $hasDon = false; $aResult = array(); $receiptPositions = Billing_Controller_ReceiptPosition::getInstance()->getPositionsByReceiptId($this->getId()); foreach ($receiptPositions as $rp) { $article = $rp->getForeignRecordBreakNull('article_id', Billing_Controller_Article::getInstance()); if ($article && $article->createsDonation()) { $donationAmount = $article->__get('donation_amount') * $rp->__get('amount'); $campaign = $article->getForeignRecordBreakNull('donation_campaign_id', Donator_Controller_Campaign::getInstance()); if ($donationAmount != 0 && $campaign) { $hasDon = true; if (!array_key_exists($campaign->getId(), $aResult)) { $aResult[$campaign->getId()] = $donationAmount; } else { $aResult[$campaign->getId()] += $donationAmount; } } } } if (!$hasDon) { return null; } return $aResult; } catch (Exception $e) { return null; } }
/** * import brevets * * @param Zend_Console_Getopt $_opts */ public function importArticles($_opts) { set_time_limit(0); parent::_import($_opts, Billing_Controller_Article::getInstance()); }
/** * * Export to DATEV * @param string $filters Json encoded filters */ public function exportFibu($filters) { set_time_limit(0); $db = Tinebase_Core::getDb(); $tm = Tinebase_TransactionManager::getInstance(); $tId = $tm->startTransaction($db); try { $filters = Zend_Json::decode($filters); $checkFilter = new Billing_Model_OpenItemFilter($filters, 'AND'); $pagination = array('sort' => 'op_nr', 'dir' => 'ASC'); $oIController = Billing_Controller_OpenItem::getInstance(); $debController = Billing_Controller_Debitor::getInstance(); $rController = Billing_Controller_Receipt::getInstance(); $oController = Billing_Controller_Order::getInstance(); $oPController = Billing_Controller_OrderPosition::getInstance(); $aController = Billing_Controller_Article::getInstance(); $cController = Addressbook_Controller_Contact::getInstance()->_setRightChecks(false)->_setContainerACLChecks(false); // if filter contains fibu_exp_date-filter -> force reexport! if (!$checkFilter->isFilterSet('fibu_exp_date')) { $fibuFilter = array('field' => 'fibu_exp_date', 'operator' => 'isnull', 'value' => ''); $filters[] = $fibuFilter; } $filter = new Billing_Model_OpenItemFilter($filters, 'AND'); $openItemIds = $oIController->search($filter, new Tinebase_Model_Pagination($pagination), false, true); /* * - Rechnungsnummer (redundant für alle Positionen) - Rechnungsdatum (redundant für alle Positionen) - Datum Fälligkeit (redundant für alle Positionen) - Debitorennummer (redundant für alle Positionen) - Betrag netto - MWST - Betrag brutto - Artikelnummer - Artikelbezeichnung - Erlöskonto (aus Artikelstamm gemäß MWST = 0 oder > 0) * Umsatz (mit Soll/Haben-Kz) Konto Gegenkonto (ohne BU-Schl�ssel) Belegdatum Belegfeld 1 Buchungstext Kennzeichen D_Opos 299,22 1000200 440000 12.01.2012 101 Rechnung101 Forderungsart "1" D_Opos * */ $csvArray = array('Umsatz (mit Soll/Haben-Kz)', 'Konto', 'Gegenkonto (ohne BU-Schlüssel)', 'Belegdatum', 'Belegfeld', 'Buchungstext', 'Kennzeichen', 'D_Opos'); /* * * - Debitorennummer - Vorname - Name - Anrede - Titel - Firma 1 - Firma 2 - Zusatz - Straße - PLZ - Ort - Land Kontonummer Unternehmen Anrede Titel Vorname Name1 Adressattyp UST ID Stra�e Postfach Postleitzahl Ort Land Bankleitzahl 1 Bankbez. 1 Bank-Kontonummer 1 Bank-L�nderkennz. 1 IBAN-Nr. 1 SWIFT-Code 1 Bankleitzahl 2 Bankbez. 2 Bank-Kontonummer2 Bank-L�nderkennz. 2 IBAN-Nr. 2 SWIFT-Code 2 5841100 Acuarios Jandia Sotavento Beach Club B.Lehmann Lehmann & Buschmann 2 DE111667148 Wefelen 27 35627 Costa-Calma/Fuerte. Spanien 70050000 Bayern LB M�nchen 2034343 DE DE14700500000002034343 BYLADEMM 5841200 Herr Prof. Dr. Hansi Gustavo 1 DE111667148 Wefelen 29 52134 Herzogenrath 39050000 Sparkasse Aachen 47176987 */ $debsArray = array('Kontonummer', 'Unternehmen', 'Anrede', 'Titel', 'Vorname', 'Name1', 'Adressattyp', 'UST ID', 'Straße', 'Postfach', 'Postleitzahl', 'Ort', 'Land', 'Bankleitzahl 1', 'Bankbez. 1', 'Bank-Kontonummer 1', 'Bank-Länderkennz. 1', 'IBAN-Nr. 1', 'SWIFT-Code 1', 'Bankbez. 2', 'Bank-Kontonummer 2', 'Bank-Länderkennz. 2', 'IBAN-Nr. 2', 'SWIFT-Code 2'); $tempFilePath = CSopen::instance()->getCustomerPath() . '/customize/data/documents/temp/'; $itemsFilename = $tempFilePath . strftime('%Y%m%d%H%M%S') . 'items_temp.csv'; $debsFilename = $tempFilePath . strftime('%Y%m%d%H%M%S') . 'debs_temp.csv'; $zipFilename = $tempFilePath . strftime('%Y%m%d%H%M%S') . 'archive_temp.csv'; if (file_exists($itemsFilename)) { unlink($itemsFilename); } $itemsFileHandle = fopen($itemsFilename, 'w'); //$filePointer, $dataArray, $delimiter=',', $enclosure='"', $escapeEnclosure='"' Tinebase_Export_Csv::fputcsvEncoding('ISO-8859-1//TRANSLIT', $itemsFileHandle, $csvArray, chr(9), '"', ''); if (file_exists($debsFilename)) { unlink($debsFilename); } $debsFileHandle = fopen($debsFilename, 'w'); Tinebase_Export_Csv::fputcsvEncoding('ISO-8859-1//TRANSLIT', $debsFileHandle, $debsArray, chr(9), '"', ''); $zeroVat = Billing_Controller_Vat::getInstance()->getByName('0'); $creditorZeroAccount = $zeroVat->__get('credit_account'); $fibuExpDate = new Zend_Date(strftime('%Y-%m-%d')); $adType = 1; foreach ($openItemIds as $openItemId) { $oI = Billing_Controller_OpenItem::getInstance()->get($openItemId); $oI->flatten(); $receiptId = $oI->__get('receipt_id'); $receipt = $rController->get($receiptId); if (!$receipt->__get('fibu_exp_date')) { $receipt->__set('fibu_exp_date', $fibuExpDate); $receipt->flatten(); //print_r($receipt); $rController->update($receipt); } $oI->__set('fibu_exp_date', $fibuExpDate); $oIController->update($oI); $positions = $rController->getOrderPositions($receiptId); //$sums = $rController->getReceiptSumValues($receiptId); $orderId = $receipt->__get('order_id'); $order = $oController->get($orderId); $debitor = $order->__get('debitor_id'); $debitorNr = $debitor->__get('debitor_nr'); $contact = $debitor->getForeignRecord('contact_id', $cController); $debitor->flatten(); $contactId = $debitor->__get('contact_id'); $name = $contact->__get('n_fileas'); $receiptNr = $oI->__get('receipt_nr'); $adType = 1; if ($contact->__get('org_name') && $contact->getLetterDrawee()->isCompany()) { $adType = 2; } $dueDate = $receipt->__get('due_date'); if (!$debitor->__get('fibu_exp_date')) { $drawee = $contact->getInvoiceDrawee(); $postal = $drawee->getPostalAddress(); $pf = ''; $street = ''; if (strpos($postal->getStreet(), 'Post')) { $pf = $postal->getStreet(); } else { $street = $postal->getStreet(); } // export debitor $debsArray = array($debitorNr, $contact->__get('org_name'), $drawee->getSalutationText(), $drawee->getTitle(), $contact->__get('n_given'), $contact->__get('n_family'), $adType, $debitor->__get('ust_id'), $street, $pf, $postal->getPostalCode(), $postal->getLocation(), $postal->getCountryCode('DE'), $contact->__get('bank_code'), $contact->__get('bank_name'), $contact->__get('bank_account_number'), trim($contact->__get('bank_code')) ? $postal->getCountryCode() : '', '', '', '', '', '', '', '', ''); Tinebase_Export_Csv::fputcsvEncoding('ISO-8859-1//TRANSLIT', $debsFileHandle, $debsArray, chr(9), '"', ''); $debitor->__set('fibu_exp_date', new Zend_Date()); $debController->update($debitor); } // $values = array(); // $values[] = array( // 'value' => $sums['total']['sum']['netto'], // 'credit_account' => $creditorZeroAccount // ); // // foreach($sums['vat_sums'] as $vatSum){ // $values[] = array( // 'value' => $vatSum['sum']['netto'], // 'credit_account' => $vatSum['sum']['vatcreditaccount'] // ); // } //Umsatz (mit Soll/Haben-Kz) Konto Gegenkonto (ohne BU-Schl�ssel) Belegdatum Belegfeld 1 Buchungstext Kennzeichen D_Opos //299,22 1000200 440000 12.01.2012 101 Rechnung101 Forderungsart "1" D_Opos $receiptText = ''; if ($receipt->__get('type') == Billing_Model_Receipt::TYPE_INVOICE) { $receiptText = 'Rechnung'; $receiptDate = $receipt->__get('invoice_date'); $receiptNr = $receipt->__get('invoice_nr'); } else { $receiptText = 'Gutschrift'; $receiptDate = $receipt->__get('credit_date'); $receiptNr = $receipt->__get('credit_nr'); } $bookingText = $receiptText . $receiptNr; /*if($oI->__get('usage')){ $bookingText = $oI->__get('usage'); }*/ $paymentMethodId = $receipt->getForeignId('payment_method_id'); $mapPaymentMethod = array('PREPAYMENT' => 1, 'BANKTRANSFER' => 2, 'DEBIT' => 3, 'CASH' => 4, 'CREDITCARD' => 5, 'PAYPAL' => 6, 'IMMEDIATETRANSFER' => 7); $intPaymentMethod = $mapPaymentMethod[$paymentMethodId]; foreach ($positions as $position) { $brutto = $position->__get('total_brutto'); //$vatSum = $oPController->getVatSum($position); //$article = $position->getForeignRecord('article_id', $aController); //$articleName = $article->__get('name'); //$articleNr = $article->__get('article_nr'); $revAccount = $oPController->getRevenueAccountAccordingToVat($position) . '00'; $csvArray = array(number_format($brutto, 2, ',', '.'), $debitorNr, $revAccount, \org\sopen\app\util\format\Date::format($receiptDate), $receiptNr, $bookingText, 'Forderungsart ' . $intPaymentMethod, 'D_Opos'); Tinebase_Export_Csv::fputcsvEncoding('ISO-8859-1//TRANSLIT', $itemsFileHandle, $csvArray, chr(9), '"', ''); } } fclose($itemsFileHandle); fclose($debsFileHandle); // -> generate zip archive containing Debitoren.csv and Forderungen.csv $zip = new ZipArchive(); $zipFile = $zipFilename . ".zip"; if ($zip->open($zipFile, ZIPARCHIVE::CREATE) !== TRUE) { exit("cannot open <{$zipFile}>\n"); } $zip->addFile($debsFilename, 'Debitoren.csv'); $zip->addFile($itemsFilename, 'Forderungen.csv'); $zip->close(); $tm->commitTransaction($tId); } catch (Exception $e) { $tm->rollback($tId); echo $e->__toString(); exit; } header("Content-type: application/zip;\n"); header("Content-Transfer-Encoding: binary"); $len = filesize($zipFile); header("Content-Length: {$len};\n"); header("Content-Disposition: attachment; filename=\"DATEV.zip\";\n\n"); readfile($zipFile); unlink($zipFile); unlink($debsFilename); unlink($itemsFilename); }
public function getRevenueAccountAccordingToVat($orderPosition) { $vatValue = $orderPosition->getForeignRecord('vat_id', Billing_Controller_Vat::getInstance())->__get('value'); $article = $orderPosition->getForeignRecord('article_id', Billing_Controller_Article::getInstance()); if ($vatValue > 0) { $acc = $article->__get('rev_account_vat_in'); } else { $acc = $article->__get('rev_account_vat_ex'); } return $acc; }