示例#1
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;
 }
示例#2
0
 protected function search($params, $categories)
 {
     $processesDb = new Processes_Model_DbTable_Process();
     $columns = array('p.title', 'p.customerid', 'p.billingname1', 'p.billingname2', 'p.billingdepartment', 'p.billingstreet', 'p.billingpostcode', 'p.billingcity', 'p.shippingname1', 'p.shippingname2', 'p.shippingdepartment', 'p.shippingstreet', 'p.shippingpostcode', 'p.shippingcity');
     $query = '';
     $schema = 'p';
     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['paymentstatus']) {
         $query = $this->_helper->Query->getQueryPaymentstatus($query, $params['paymentstatus'], $schema);
     }
     if ($params['catid']) {
         $processes = $processesDb->fetchAll($processesDb->select()->setIntegrityCheck(false)->from(array('p' => 'process'))->join(array('c' => 'contact'), 'p.customerid = c.id', array('catid'))->group($schema . '.id')->where($query ? $query : 1)->order($params['order'] . ' ' . $params['sort'])->limit($params['limit']));
         if (!count($processes) && $params['keyword']) {
             $this->_flashMessenger->addMessage('MESSAGES_SEARCH_RETURNED_NO_RESULTS');
             $query = $this->_helper->Query->getQueryKeyword('', $params['keyword'], $columns);
             $processes = $processesDb->fetchAll($processesDb->select()->setIntegrityCheck(false)->from(array('p' => 'process'))->join(array('c' => 'contact'), 'p.customerid = c.id', array('catid'))->group($schema . '.id')->where($query ? $query : 1)->order($params['order'] . ' ' . $params['sort'])->limit($params['limit']));
         }
     } else {
         $processes = $processesDb->fetchAll($processesDb->select()->setIntegrityCheck(false)->from(array('p' => 'process'))->group($schema . '.id')->where($query ? $query : 1)->order($params['order'] . ' ' . $params['sort'])->limit($params['limit']));
         if (!count($processes) && $params['keyword']) {
             $this->_flashMessenger->addMessage('MESSAGES_SEARCH_RETURNED_NO_RESULTS');
             $query = $this->_helper->Query->getQueryKeyword('', $params['keyword'], $columns);
             $processes = $processesDb->fetchAll($processesDb->select()->setIntegrityCheck(false)->from(array('p' => 'process'))->group($schema . '.id')->where($query ? $query : 1)->order($params['order'] . ' ' . $params['sort'])->limit($params['limit']));
         }
     }
     $processes->subtotal = 0;
     $processes->total = 0;
     foreach ($processes as $process) {
         $processes->subtotal += $process->subtotal;
         $processes->total += $process->total;
         if ($process->prepayment == 0.0) {
             $process->prepayment = 0;
         } else {
             //$process->stillToPay = $this->_currency->toCurrency($processes->subtotal-$process->prepayment);
             $process->prepayment = $this->_currency->toCurrency($process->prepayment);
         }
         if ($process->total == 0.0) {
             $process->total = 0;
         } else {
             $process->total = $this->_currency->toCurrency($process->total);
         }
         if ($process->prepaymenttotal == 0.0) {
             $process->prepaymenttotal = 0;
         } else {
             $process->prepaymenttotal = $this->_currency->toCurrency($process->prepaymenttotal);
         }
         if ($process->creditnotetotal == 0.0) {
             $process->creditnotetotal = 0;
         } else {
             $process->creditnotetotal = $this->_currency->toCurrency($process->creditnotetotal);
         }
     }
     $processes->total = $this->_currency->toCurrency($processes->total);
     return $processes;
 }