public function indexAction()
 {
     $this->_helper->getHelper('layout')->disableLayout();
     $creditnoteid = $this->_getParam('creditnoteid', 0);
     $locale = Zend_Registry::get('Zend_Locale');
     //Get creditnote
     $creditnoteDb = new Sales_Model_DbTable_Creditnote();
     $creditnote = $creditnoteDb->getCreditnote($creditnoteid);
     //Get positions
     $positions = $this->getPositions($creditnoteid);
     //Get units of measurements
     $uoms = $this->_helper->Uom->getUoms();
     $uoms = array_combine($uoms, $uoms);
     //Get tax rates
     $taxRates = $this->_helper->TaxRate->getTaxRates($locale);
     $forms = array();
     $orderings = array();
     foreach ($positions as $position) {
         $orderings[$position->ordering] = $position->ordering;
     }
     foreach ($positions as $position) {
         $position->total = $this->_currency->toCurrency($position->price * $position->quantity);
         $position->price = $this->_currency->toCurrency($position->price);
         $position->quantity = Zend_Locale_Format::toNumber($position->quantity, array('precision' => 2, 'locale' => $locale));
         $form = new Sales_Form_Creditnotepos();
         $forms[$position->id] = $form->populate($position->toArray());
         $forms[$position->id]->uom->addMultiOptions($uoms);
         $forms[$position->id]->taxrate->addMultiOptions($taxRates);
         $forms[$position->id]->ordering->addMultiOptions($orderings);
     }
     $creditnote['subtotal'] = $this->_currency->toCurrency($creditnote['subtotal']);
     $creditnote['taxes'] = $this->_currency->toCurrency($creditnote['taxes']);
     $creditnote['total'] = $this->_currency->toCurrency($creditnote['total']);
     $this->view->forms = $forms;
     $this->view->creditnote = $creditnote;
     $this->view->toolbar = new Sales_Form_ToolbarPositions();
 }
Example #2
0
 public function createCharts($lenght, $width = 1000, $height = 400, $statisticsUncategorized, $params, $options)
 {
     //print_r($params);
     //print_r($options);
     $year = date('Y');
     $month = date('m');
     $y = date('Y', strtotime('-' . ($lenght - 1) . ' month'));
     $m = date('m', strtotime('-' . ($lenght - 1) . ' month'));
     $user = Zend_Registry::get('User');
     $invoicesDb = new Sales_Model_DbTable_Invoice();
     $creditnotesDb = new Sales_Model_DbTable_Creditnote();
     $turnover = array();
     $turnoverCategories = array();
     while ($y <= $year) {
         while ($m) {
             if ($y < $year || $m <= $month) {
                 //Get invoices
                 $ym = str_pad($m, 2, '0', STR_PAD_LEFT);
                 $query = 'i.state = 105';
                 $query .= " AND (invoicedate BETWEEN '" . $y . "-" . $ym . "-" . "01' AND '" . $y . "-" . $ym . "-" . "31')";
                 $query .= ' AND i.clientid = ' . $user['clientid'];
                 $query .= ' AND c.clientid = ' . $user['clientid'];
                 if ($params['catid']) {
                     $query = Zend_Controller_Action_HelperBroker::getStaticHelper('Query')->getQueryCategory($query, $params['catid'], $options['categories'], 'c');
                 }
                 if ($params['country']) {
                     $query = Zend_Controller_Action_HelperBroker::getStaticHelper('Query')->getQueryCountry($query, $params['country'], 'i');
                 }
                 $invoices = $invoicesDb->fetchAll($invoicesDb->select()->from(array('i' => 'invoice'))->join(array('c' => 'contact'), 'i.contactid = c.id', array('catid'))->where($query ? $query : 1)->setIntegrityCheck(false));
                 //Get credit notes
                 $ym = str_pad($m, 2, '0', STR_PAD_LEFT);
                 $query = 'i.state = 105';
                 $query .= " AND (creditnotedate BETWEEN '" . $y . "-" . $ym . "-" . "01' AND '" . $y . "-" . $ym . "-" . "31')";
                 $query .= ' AND i.clientid = ' . $user['clientid'];
                 $query .= ' AND c.clientid = ' . $user['clientid'];
                 if ($params['catid']) {
                     $query = Zend_Controller_Action_HelperBroker::getStaticHelper('Query')->getQueryCategory($query, $params['catid'], $options['categories'], 'c');
                 }
                 if ($params['country']) {
                     $query = Zend_Controller_Action_HelperBroker::getStaticHelper('Query')->getQueryCountry($query, $params['country'], 'i');
                 }
                 $creditnotes = $creditnotesDb->fetchAll($creditnotesDb->select()->from(array('i' => 'creditnote'))->join(array('c' => 'contact'), 'i.contactid = c.id', array('catid'))->where($query ? $query : 1)->setIntegrityCheck(false));
                 $turnover[$y . $ym] = 0;
                 $turnoverCategories[0][$y . $ym] = 0;
                 //Calculate invoices
                 foreach ($invoices as $invoice) {
                     $turnover[$y . $ym] += $invoice->subtotal;
                     if (isset($turnoverCategories[$invoice->catid][$y . $ym])) {
                         $turnoverCategories[$invoice->catid][$y . $ym] += $invoice->subtotal;
                     } else {
                         $turnoverCategories[$invoice->catid][$y . $ym] = $invoice->subtotal;
                     }
                 }
                 //Calculate credit notes
                 foreach ($creditnotes as $creditnote) {
                     $turnover[$y . $ym] -= $creditnote->subtotal;
                     if (isset($turnoverCategories[$creditnote->catid][$y . $ym])) {
                         $turnoverCategories[$creditnote->catid][$y . $ym] += $creditnote->subtotal;
                     } else {
                         $turnoverCategories[$creditnote->catid][$y . $ym] = $creditnote->subtotal;
                     }
                 }
                 //Calculate categories
                 foreach ($options['categories'] as $id => $category) {
                     if (isset($turnoverCategories[$id][$y . $ym])) {
                         $turnoverCategories[$id][$y . $ym] = round($turnoverCategories[$id][$y . $ym]);
                     } else {
                         $turnoverCategories[$id][$y . $ym] = 0;
                     }
                 }
                 $turnover[$y . $ym] = round($turnover[$y . $ym]);
                 $turnoverCategories[0][$y . $ym] = round($turnoverCategories[0][$y . $ym]);
                 $dataDb = 'total:' . $turnover[$y . $ym] . ';';
                 foreach ($turnoverCategories as $key => $value) {
                     if (isset($value[$y . $ym])) {
                         $dataDb .= $key . ':' . $value[$y . $ym] . ';';
                     }
                 }
                 //$archiveDb->addArchive($y.$ym, $dataDb, $user['clientid']);
                 $months[$y . $ym] = $y . '/' . $ym;
             }
             ++$m;
             if ($m > 12) {
                 $m = 0;
             }
         }
         ++$y;
         $m = 1;
     }
     //Merge subcategories to main categories
     foreach ($turnoverCategories as $id => $values) {
         if (isset($options['categories'][$id]['childs']) && $id != $params['catid']) {
             foreach ($options['categories'][$id]['childs'] as $childId) {
                 foreach ($values as $month => $value) {
                     $turnoverCategories[$id][$month] += $turnoverCategories[$childId][$month];
                 }
                 unset($turnoverCategories[$childId]);
             }
         }
     }
     //Remove empty arrays
     foreach ($turnoverCategories as $key => $values) {
         if (!array_sum($values)) {
             unset($turnoverCategories[$key]);
         }
     }
     require_once BASE_PATH . '/library/pChart/class/pData.class.php';
     require_once BASE_PATH . '/library/pChart/class/pDraw.class.php';
     require_once BASE_PATH . '/library/pChart/class/pImage.class.php';
     //Turnover
     /* Create your dataset object */
     $turnoverData = new pData();
     /* Add data in your dataset */
     $turnoverData->addPoints($turnover, 'Values');
     $turnoverData->setAxisName(0, '€ / Netto');
     /* Create the X serie */
     $turnoverData->addPoints($months, 'Labels');
     $turnoverData->setSerieDescription('Labels', 'Months');
     $turnoverData->setAbscissa('Labels');
     /* Create a pChart object and associate your dataset */
     $turnover = new pImage($width, $height, $turnoverData);
     /* Turn off AA processing */
     $turnover->Antialias = FALSE;
     /* Choose a nice font */
     $turnover->setFontProperties(array('FontName' => BASE_PATH . '/library/pChart/fonts/verdana.ttf', 'FontSize' => 10));
     /* Define the boundaries of the graph area */
     $turnover->setGraphArea(75, 20, $width - 30, $height - 60);
     /* Draw the scale, keep everything automatic */
     $turnover->drawScale(array('DrawSubTicks' => TRUE, 'Mode' => SCALE_MODE_START0, 'LabelRotation' => 45));
     /* Draw the scale, keep everything automatic */
     $settings = array('Gradient' => TRUE, 'GradientMode' => GRADIENT_EFFECT_CAN, 'DisplayPos' => LABEL_POS_INSIDE, 'DisplayValues' => TRUE, 'DisplayR' => 0, 'DisplayG' => 0, 'DisplayB' => 0, 'DisplayShadow' => TRUE, 'Surrounding' => 10);
     $turnover->drawBarChart($settings);
     /* Build the PNG file and send it to the web browser */
     if (!file_exists(BASE_PATH . '/cache/chart/')) {
         mkdir(BASE_PATH . '/cache/chart/');
         chmod(BASE_PATH . '/cache/chart/', 0777);
     }
     $turnover->Render(BASE_PATH . '/cache/chart/turnover-' . $width . '-' . $height . '.png');
     //Turnover by categories
     /* Create your dataset object */
     $turnoverCategoriesData = new pData();
     /* Add data in your dataset */
     $turnoverCategoriesTotal = array();
     foreach ($turnoverCategories as $key => $value) {
         $turnoverCategoriesTotal[$key] = array_sum($value);
     }
     arsort($turnoverCategoriesTotal);
     foreach ($turnoverCategoriesTotal as $key => $value) {
         if ($key && isset($options['categories'][$key])) {
             $turnoverCategoriesData->addPoints($turnoverCategories[$key], $options['categories'][$key]['title']);
         }
     }
     if (isset($turnoverCategories[0])) {
         $turnoverCategoriesData->addPoints($turnoverCategories[0], $statisticsUncategorized);
     }
     $turnoverCategoriesData->setAxisName(0, '€ / Netto');
     /* Create the X serie */
     $turnoverCategoriesData->addPoints($months, 'Labels');
     $turnoverCategoriesData->setSerieDescription('Labels', 'Months');
     $turnoverCategoriesData->setAbscissa('Labels');
     /* Create a pChart object and associate your dataset */
     $turnoverCategories = new pImage($width, $height, $turnoverCategoriesData);
     /* Turn off AA processing */
     $turnoverCategories->Antialias = FALSE;
     /* Choose a nice font */
     $turnoverCategories->setFontProperties(array('FontName' => BASE_PATH . '/library/pChart/fonts/verdana.ttf', 'FontSize' => 10));
     /* Define the boundaries of the graph area */
     $turnoverCategories->setGraphArea(75, 20, $width - 30, $height - 60);
     /* Draw the scale, keep everything automatic */
     $turnoverCategories->drawScale(array('XMargin' => 2, 'DrawSubTicks' => TRUE, 'Mode' => SCALE_MODE_ADDALL_START0, 'LabelRotation' => 45));
     /* Draw the scale, keep everything automatic */
     $settings = array();
     $turnoverCategories->drawStackedAreaChart($settings);
     /* Write the chart legend */
     $turnoverCategories->drawLegend(100, 20, array('Style' => LEGEND_NOBORDER, 'Mode' => LEGEND_VERTICAL));
     /* Build the PNG file and send it to the web browser */
     $turnoverCategories->Render(BASE_PATH . '/cache/chart/turnover-category-' . $width . '-' . $height . '.png');
 }
Example #3
0
 protected function search($params, $categories)
 {
     $creditnotesDb = new Sales_Model_DbTable_Creditnote();
     $columns = array('cr.title', 'cr.creditnoteid', 'cr.contactid', 'cr.billingname1', 'cr.billingname2', 'cr.billingdepartment', 'cr.billingstreet', 'cr.billingpostcode', 'cr.billingcity', 'cr.shippingname1', 'cr.shippingname2', 'cr.shippingdepartment', 'cr.shippingstreet', 'cr.shippingpostcode', 'cr.shippingcity');
     $query = '';
     $schema = 'cr';
     if ($params['keyword']) {
         $query = $this->_helper->Query->getQueryKeyword($query, $params['keyword'], $columns);
     }
     if ($params['catid']) {
         $query = $this->_helper->Query->getQueryCategory($query, $params['catid'], $categories, 'c');
     }
     if ($params['states']) {
         $query = $this->_helper->Query->getQueryStates($query, $params['states'], $schema);
     }
     if ($params['daterange']) {
         $query = $this->_helper->Query->getQueryDaterange($query, $params['from'], $params['to'], $schema);
     }
     if ($params['country']) {
         $query = $this->_helper->Query->getQueryCountry($query, $params['country'], $schema);
     }
     if ($params['catid']) {
         $creditnotes = $creditnotesDb->fetchAll($creditnotesDb->select()->setIntegrityCheck(false)->from(array($schema => 'creditnote'))->join(array('c' => 'contact'), $schema . '.contactid = c.id', array('catid'))->group($schema . '.id')->where($query ? $query : 1)->order($params['order'] . ' ' . $params['sort'])->limit($params['limit']));
         if (!count($creditnotes) && $params['keyword']) {
             $this->_flashMessenger->addMessage('MESSAGES_SEARCH_RETURNED_NO_RESULTS');
             $query = $this->_helper->Query->getQueryKeyword('', $params['keyword'], $columns);
             $creditnotes = $creditnotesDb->fetchAll($creditnotesDb->select()->setIntegrityCheck(false)->from(array($schema => 'creditnote'))->join(array('c' => 'contact'), $schema . '.contactid = c.id', array('catid'))->group($schema . '.id')->where($query ? $query : 1)->order($params['order'] . ' ' . $params['sort'])->limit($params['limit']));
         }
     } else {
         $creditnotes = $creditnotesDb->fetchAll($creditnotesDb->select()->setIntegrityCheck(false)->from(array($schema => 'creditnote'))->group($schema . '.id')->where($query ? $query : 1)->order($params['order'] . ' ' . $params['sort'])->limit($params['limit']));
         if (!count($creditnotes) && $params['keyword']) {
             $this->_flashMessenger->addMessage('MESSAGES_SEARCH_RETURNED_NO_RESULTS');
             $query = $this->_helper->Query->getQueryKeyword('', $params['keyword'], $columns);
             $creditnotes = $creditnotesDb->fetchAll($creditnotesDb->select()->setIntegrityCheck(false)->from(array($schema => 'creditnote'))->group($schema . '.id')->where($query ? $query : 1)->order($params['order'] . ' ' . $params['sort'])->limit($params['limit']));
         }
     }
     $creditnotes->subtotal = 0;
     $creditnotes->total = 0;
     foreach ($creditnotes as $creditnote) {
         $creditnotes->subtotal += $creditnote->subtotal;
         $creditnotes->total += $creditnote->total;
         $creditnote->subtotal = $this->_currency->toCurrency($creditnote->subtotal);
         $creditnote->taxes = $this->_currency->toCurrency($creditnote->taxes);
         $creditnote->total = $this->_currency->toCurrency($creditnote->total);
     }
     $creditnotes->subtotal = $this->_currency->toCurrency($creditnotes->subtotal);
     $creditnotes->total = $this->_currency->toCurrency($creditnotes->total);
     return $creditnotes;
 }
Example #4
0
 public function generatecreditnoteAction()
 {
     $id = $this->_getParam('id', 0);
     $invoiceDb = new Sales_Model_DbTable_Invoice();
     $data = $invoiceDb->getInvoice($id);
     unset($data['id'], $data['invoiceid'], $data['invoicedate'], $data['ebayorderid']);
     $data['creditnotedate'] = '0000-00-00';
     $data['state'] = 100;
     $data['created'] = $this->_date;
     $data['createdby'] = $this->_user['id'];
     $data['modified'] = '0000-00-00';
     $data['modifiedby'] = 0;
     $data['clientid'] = $this->_user['clientid'];
     $creditnote = new Sales_Model_DbTable_Creditnote();
     $creditnoteid = $creditnote->addCreditnote($data);
     $positions = $this->getPositions($id);
     $positionsCreditnoteDb = new Sales_Model_DbTable_Creditnotepos();
     foreach ($positions as $position) {
         $dataPosition = $position->toArray();
         $dataPosition['creditnoteid'] = $creditnoteid;
         $dataPosition['created'] = $this->_date;
         $dataPosition['createdby'] = $this->_user['id'];
         $dataPosition['modified'] = '0000-00-00';
         $dataPosition['modifiedby'] = 0;
         unset($dataPosition['id'], $dataPosition['invoiceid']);
         $positionsCreditnoteDb->addPosition($dataPosition);
     }
     $this->_flashMessenger->addMessage('MESSAGES_CREDIT_NOTE_SUCCESFULLY_GENERATED');
     $this->_helper->redirector->gotoSimple('edit', 'creditnote', null, array('id' => $creditnoteid));
 }
Example #5
0
 protected function getHistory($id)
 {
     $this->_currency->setFormat(array('display' => Zend_Currency::USE_SYMBOL));
     $documentrelationDb = new Application_Model_DbTable_Documentrelation();
     $documentrelations = $documentrelationDb->fetchAll($documentrelationDb->select()->where('contactid = ?', $id));
     $documentrelationIDs = array();
     foreach ($documentrelations as $documentrelation) {
         if (!isset($documentrelationIDs[$documentrelation['module']][$documentrelation['controller']])) {
             $documentrelationIDs[$documentrelation['module']][$documentrelation['controller']] = array();
         }
         array_push($documentrelationIDs[$documentrelation['module']][$documentrelation['controller']], $documentrelation['documentid']);
     }
     //Quotes
     $quoteDb = new Sales_Model_DbTable_Quote();
     if (isset($documentrelationIDs['sales']['quote'])) {
         $history['quotes'] = $quoteDb->fetchAll($quoteDb->select()->where('contactid = ?', $id)->where('clientid = ?', $this->_user['clientid'])->orWhere('id IN (?)', $documentrelationIDs['sales']['quote'])->where('clientid = ?', $this->_user['clientid']));
     } else {
         $history['quotes'] = $quoteDb->fetchAll($quoteDb->select()->where('contactid = ?', $id)->where('clientid = ?', $this->_user['clientid']));
     }
     foreach ($history['quotes'] as $quote) {
         $quote->subtotal = $this->_currency->toCurrency($quote->subtotal);
         $quote->taxes = $this->_currency->toCurrency($quote->taxes);
         $quote->total = $this->_currency->toCurrency($quote->total);
         if ($quote->quotedate && $quote->quotedate != '0000-00-00') {
             $quote->quotedate = date('d.m.Y', strtotime($quote->quotedate));
         }
         if ($quote->modified && $quote->modified != '0000-00-00') {
             $quote->modified = date('d.m.Y', strtotime($quote->modified));
         }
         if ($quote->deliverydate && $quote->deliverydate != '0000-00-00') {
             $quote->deliverydate = date('d.m.Y', strtotime($quote->deliverydate));
         }
     }
     //Sales orders
     $salesorderDb = new Sales_Model_DbTable_Salesorder();
     if (isset($documentrelationIDs['sales']['salesorder'])) {
         $history['salesorders'] = $salesorderDb->fetchAll($salesorderDb->select()->where('contactid = ?', $id)->where('clientid = ?', $this->_user['clientid'])->orWhere('id IN (?)', $documentrelationIDs['sales']['salesorder'])->where('clientid = ?', $this->_user['clientid']));
     } else {
         $history['salesorders'] = $salesorderDb->fetchAll($salesorderDb->select()->where('contactid = ?', $id)->where('clientid = ?', $this->_user['clientid']));
     }
     foreach ($history['salesorders'] as $salesorder) {
         $salesorder->subtotal = $this->_currency->toCurrency($salesorder->subtotal);
         $salesorder->taxes = $this->_currency->toCurrency($salesorder->taxes);
         $salesorder->total = $this->_currency->toCurrency($salesorder->total);
         if ($salesorder->salesorderdate && $salesorder->salesorderdate != '0000-00-00') {
             $salesorder->salesorderdate = date('d.m.Y', strtotime($salesorder->salesorderdate));
         }
         if ($salesorder->modified && $salesorder->modified != '0000-00-00') {
             $salesorder->modified = date('d.m.Y', strtotime($salesorder->modified));
         }
         if ($salesorder->deliverydate && $salesorder->deliverydate != '0000-00-00') {
             $salesorder->deliverydate = date('d.m.Y', strtotime($salesorder->deliverydate));
         }
     }
     //Invoices
     $invoiceDb = new Sales_Model_DbTable_Invoice();
     if (isset($documentrelationIDs['sales']['invoice'])) {
         $history['invoices'] = $invoiceDb->fetchAll($invoiceDb->select()->where('contactid = ?', $id)->where('clientid = ?', $this->_user['clientid'])->orWhere('id IN (?)', $documentrelationIDs['sales']['invoice'])->where('clientid = ?', $this->_user['clientid']));
     } else {
         $history['invoices'] = $invoiceDb->fetchAll($invoiceDb->select()->where('contactid = ?', $id)->where('clientid = ?', $this->_user['clientid']));
     }
     foreach ($history['invoices'] as $invoice) {
         $invoice->subtotal = $this->_currency->toCurrency($invoice->subtotal);
         $invoice->taxes = $this->_currency->toCurrency($invoice->taxes);
         $invoice->total = $this->_currency->toCurrency($invoice->total);
         if ($invoice->invoicedate && $invoice->invoicedate != '0000-00-00') {
             $invoice->invoicedate = date('d.m.Y', strtotime($invoice->invoicedate));
         }
         if ($invoice->modified && $invoice->modified != '0000-00-00') {
             $invoice->modified = date('d.m.Y', strtotime($invoice->modified));
         }
         if ($invoice->deliverydate && $invoice->deliverydate != '0000-00-00') {
             $invoice->deliverydate = date('d.m.Y', strtotime($invoice->deliverydate));
         }
     }
     //Delivery orders
     $deliveryorderDb = new Sales_Model_DbTable_Deliveryorder();
     if (isset($documentrelationIDs['sales']['deliveryorder'])) {
         $history['deliveryorders'] = $deliveryorderDb->fetchAll($deliveryorderDb->select()->where('contactid = ?', $id)->where('clientid = ?', $this->_user['clientid'])->orWhere('id IN (?)', $documentrelationIDs['sales']['deliveryorder'])->where('clientid = ?', $this->_user['clientid']));
     } else {
         $history['deliveryorders'] = $deliveryorderDb->fetchAll($deliveryorderDb->select()->where('contactid = ?', $id)->where('clientid = ?', $this->_user['clientid']));
     }
     foreach ($history['deliveryorders'] as $deliveryorder) {
         $deliveryorder->subtotal = $this->_currency->toCurrency($deliveryorder->subtotal);
         $deliveryorder->taxes = $this->_currency->toCurrency($deliveryorder->taxes);
         $deliveryorder->total = $this->_currency->toCurrency($deliveryorder->total);
         if ($deliveryorder->deliveryorderdate && $deliveryorder->deliveryorderdate != '0000-00-00') {
             $deliveryorder->deliveryorderdate = date('d.m.Y', strtotime($deliveryorder->deliveryorderdate));
         }
         if ($deliveryorder->modified && $deliveryorder->modified != '0000-00-00') {
             $deliveryorder->modified = date('d.m.Y', strtotime($deliveryorder->modified));
         }
         if ($deliveryorder->deliverydate && $deliveryorder->deliverydate != '0000-00-00') {
             $deliveryorder->deliverydate = date('d.m.Y', strtotime($deliveryorder->deliverydate));
         }
     }
     //Credit notes
     $creditnoteDb = new Sales_Model_DbTable_Creditnote();
     if (isset($documentrelationIDs['sales']['creditnote'])) {
         $history['creditnotes'] = $creditnoteDb->fetchAll($creditnoteDb->select()->where('contactid = ?', $id)->where('clientid = ?', $this->_user['clientid'])->orWhere('id IN (?)', $documentrelationIDs['sales']['creditnote'])->where('clientid = ?', $this->_user['clientid']));
     } else {
         $history['creditnotes'] = $creditnoteDb->fetchAll($creditnoteDb->select()->where('contactid = ?', $id)->where('clientid = ?', $this->_user['clientid']));
     }
     foreach ($history['creditnotes'] as $creditnote) {
         $creditnote->subtotal = $this->_currency->toCurrency($creditnote->subtotal);
         $creditnote->taxes = $this->_currency->toCurrency($creditnote->taxes);
         $creditnote->total = $this->_currency->toCurrency($creditnote->total);
         if ($creditnote->creditnotedate && $creditnote->creditnotedate != '0000-00-00') {
             $creditnote->creditnotedate = date('d.m.Y', strtotime($creditnote->creditnotedate));
         }
         if ($creditnote->modified && $creditnote->modified != '0000-00-00') {
             $creditnote->modified = date('d.m.Y', strtotime($creditnote->modified));
         }
         if ($creditnote->deliverydate && $creditnote->deliverydate != '0000-00-00') {
             $creditnote->deliverydate = date('d.m.Y', strtotime($creditnote->deliverydate));
         }
     }
     //Quote requests
     $quoterequestDb = new Purchases_Model_DbTable_Quoterequest();
     if (isset($documentrelationIDs['purchases']['quoterequest'])) {
         $history['quoterequests'] = $quoterequestDb->fetchAll($quoterequestDb->select()->where('contactid = ?', $id)->where('clientid = ?', $this->_user['clientid'])->orWhere('id IN (?)', $documentrelationIDs['purchases']['quoterequest'])->where('clientid = ?', $this->_user['clientid']));
     } else {
         $history['quoterequests'] = $quoterequestDb->fetchAll($quoterequestDb->select()->where('contactid = ?', $id)->where('clientid = ?', $this->_user['clientid']));
     }
     foreach ($history['quoterequests'] as $quoterequest) {
         $quoterequest->subtotal = $this->_currency->toCurrency($quoterequest->subtotal);
         $quoterequest->taxes = $this->_currency->toCurrency($quoterequest->taxes);
         $quoterequest->total = $this->_currency->toCurrency($quoterequest->total);
         if ($quoterequest->quoterequestdate && $quoterequest->quoterequestdate != '0000-00-00') {
             $quoterequest->quoterequestdate = date('d.m.Y', strtotime($quoterequest->quoterequestdate));
         }
         if ($quoterequest->modified && $quoterequest->modified != '0000-00-00') {
             $quoterequest->modified = date('d.m.Y', strtotime($quoterequest->modified));
         }
         if ($quoterequest->deliverydate && $quoterequest->deliverydate != '0000-00-00') {
             $quoterequest->deliverydate = date('d.m.Y', strtotime($quoterequest->deliverydate));
         }
     }
     //Purchase orders
     $purchaseorderDb = new Purchases_Model_DbTable_Purchaseorder();
     if (isset($documentrelationIDs['purchases']['purchaseorder'])) {
         $history['purchaseorders'] = $purchaseorderDb->fetchAll($purchaseorderDb->select()->where('contactid = ?', $id)->where('clientid = ?', $this->_user['clientid'])->orWhere('id IN (?)', $documentrelationIDs['purchases']['purchaseorder'])->where('clientid = ?', $this->_user['clientid']));
     } else {
         $history['purchaseorders'] = $purchaseorderDb->fetchAll($purchaseorderDb->select()->where('contactid = ?', $id)->where('clientid = ?', $this->_user['clientid']));
     }
     foreach ($history['purchaseorders'] as $purchaseorder) {
         $purchaseorder->subtotal = $this->_currency->toCurrency($purchaseorder->subtotal);
         $purchaseorder->taxes = $this->_currency->toCurrency($purchaseorder->taxes);
         $purchaseorder->total = $this->_currency->toCurrency($purchaseorder->total);
     }
     //Processes
     $processesDb = new Processes_Model_DbTable_Process();
     $history['processes'] = $processesDb->fetchAll($processesDb->select()->where('customerid = ?', $id));
     /*foreach($history['processes'] as $process) {
     			$process->subtotal = $this->_currency->toCurrency($process->subtotal);
     			$process->taxes = $this->_currency->toCurrency($process->taxes);
     			$process->total = $this->_currency->toCurrency($process->total);
     		}*/
     return $history;
 }