Esempio n. 1
0
 public function indexAction()
 {
     $toolbar = new Statistics_Form_Toolbar();
     $options = $this->_helper->Options->getOptions($toolbar, $this->_user['clientid']);
     $params = $this->_helper->Params->getParams($toolbar, $options);
     $charts = new Statistics_Model_Charts();
     $charts->createCharts(13, 500, 300, $this->view->translate('STATISTICS_UNCATEGORIZED'), $params, $options);
     $quotesDb = new Sales_Model_DbTable_Quote();
     $quotes = $quotesDb->fetchAll($quotesDb->select()->where('quoteid = ?', 0)->order('id desc')->limit(5));
     $this->view->quotes = $quotes;
     $salesordersDb = new Sales_Model_DbTable_Salesorder();
     $salesorders = $salesordersDb->fetchAll($salesordersDb->select()->where('salesorderid = ?', 0)->order('id desc')->limit(5));
     $this->view->salesorders = $salesorders;
     $invoicesDb = new Sales_Model_DbTable_Invoice();
     $invoices = $invoicesDb->fetchAll($invoicesDb->select()->where('invoiceid = ?', 0)->order('id desc')->limit(5));
     $this->view->invoices = $invoices;
     $quoterequestsDb = new Purchases_Model_DbTable_Quoterequest();
     $quoterequests = $quoterequestsDb->fetchAll($quoterequestsDb->select()->where('quoterequestid = ?', 0)->order('id desc')->limit(5));
     $this->view->quoterequests = $quoterequests;
     $purchaseordersDb = new Purchases_Model_DbTable_Purchaseorder();
     $purchaseorders = $purchaseordersDb->fetchAll($purchaseordersDb->select()->where('purchaseorderid = ?', 0)->order('id desc')->limit(5));
     $this->view->purchaseorders = $purchaseorders;
     $this->view->options = $options;
     $this->view->toolbar = new Application_Form_Toolbar();
     $this->view->messages = $this->_flashMessenger->getMessages();
 }
 public function indexAction()
 {
     $this->_helper->getHelper('layout')->disableLayout();
     $quoterequestid = $this->_getParam('quoterequestid', 0);
     $locale = Zend_Registry::get('Zend_Locale');
     //Get quoterequest
     $quoterequestDb = new Purchases_Model_DbTable_Quoterequest();
     $quoterequest = $quoterequestDb->getQuoterequest($quoterequestid);
     //Get positions
     $positions = $this->getPositions($quoterequestid);
     //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 Purchases_Form_Quoterequestpos();
         $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);
     }
     $quoterequest['subtotal'] = $this->_currency->toCurrency($quoterequest['subtotal']);
     $quoterequest['taxes'] = $this->_currency->toCurrency($quoterequest['taxes']);
     $quoterequest['total'] = $this->_currency->toCurrency($quoterequest['total']);
     $this->view->forms = $forms;
     $this->view->quoterequest = $quoterequest;
     $this->view->toolbar = new Purchases_Form_ToolbarPositions();
 }
Esempio n. 3
0
 public function generatequoterequestAction()
 {
     $id = $this->_getParam('id', 0);
     $quoteDb = new Sales_Model_DbTable_Quote();
     $data = $quoteDb->getQuote($id);
     unset($data['id'], $data['quoteid'], $data['quotedate']);
     $data['quoterequestdate'] = '0000-00-00';
     $data['billingname1'] = '';
     $data['billingname2'] = '';
     $data['billingdepartment'] = '';
     $data['billingstreet'] = '';
     $data['billingpostcode'] = '';
     $data['billingcity'] = '';
     $data['billingcountry'] = '';
     if (!$data['shippingname1']) {
         $data['shippingname1'] = $data['billingname1'];
         $data['shippingname2'] = $data['billingname2'];
         $data['shippingdepartment'] = $data['billingdepartment'];
         $data['shippingstreet'] = $data['billingstreet'];
         $data['shippingpostcode'] = $data['billingpostcode'];
         $data['shippingcity'] = $data['billingcity'];
         $data['shippingcountry'] = $data['billingcountry'];
         $data['shippingphone'] = '';
     }
     $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'];
     $quoterequest = new Purchases_Model_DbTable_Quoterequest();
     $quoterequestid = $quoterequest->addQuoterequest($data);
     $positions = $this->getPositions($id);
     $positionsQuoterequestDb = new Purchases_Model_DbTable_Quoterequestpos();
     foreach ($positions as $position) {
         $dataPosition = $position->toArray();
         $dataPosition['quoterequestid'] = $quoterequestid;
         $dataPosition['created'] = $this->_date;
         $dataPosition['createdby'] = $this->_user['id'];
         $dataPosition['modified'] = '0000-00-00';
         $dataPosition['modifiedby'] = 0;
         unset($dataPosition['id'], $dataPosition['quoteid']);
         $positionsQuoterequestDb->addPosition($dataPosition);
     }
     //Add document relation
     $documentrelationDb = new Application_Model_DbTable_Documentrelation();
     $documentrelationDb->addDocumentrelation($data['contactid'], $quoterequestid, "purchases", "quoterequest", $this->_date, $this->_user['id']);
     $this->_flashMessenger->addMessage('MESSAGES_QUOTE_REQUEST_SUCCESFULLY_GENERATED');
     $this->_helper->redirector->gotoSimple('edit', 'quoterequest', 'purchases', array('id' => $quoterequestid));
 }
Esempio n. 4
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;
 }
Esempio n. 5
0
 protected function search($params, $categories)
 {
     $quoterequestsDb = new Purchases_Model_DbTable_Quoterequest();
     $columns = array('q.title', 'q.quoteid', 'q.contactid', 'q.billingname1', 'q.billingname2', 'q.billingdepartment', 'q.billingstreet', 'q.billingpostcode', 'q.billingcity', 'q.shippingname1', 'q.shippingname2', 'q.shippingdepartment', 'q.shippingstreet', 'q.shippingpostcode', 'q.shippingcity');
     $query = '';
     $schema = 'q';
     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']) {
         $quoterequests = $quoterequestsDb->fetchAll($quoterequestsDb->select()->setIntegrityCheck(false)->from(array($schema => 'quoterequest'))->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($quoterequests) && $params['keyword']) {
             $this->_flashMessenger->addMessage('MESSAGES_SEARCH_RETURNED_NO_RESULTS');
             $query = $this->_helper->Query->getQueryKeyword('', $params['keyword'], $columns);
             $quoterequests = $quoterequestsDb->fetchAll($quoterequestsDb->select()->setIntegrityCheck(false)->from(array($schema => 'quoterequest'))->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 {
         $quoterequests = $quoterequestsDb->fetchAll($quoterequestsDb->select()->setIntegrityCheck(false)->from(array($schema => 'quoterequest'))->group($schema . '.id')->where($query ? $query : 1)->order($params['order'] . ' ' . $params['sort'])->limit($params['limit']));
         if (!count($quoterequests) && $params['keyword']) {
             $this->_flashMessenger->addMessage('MESSAGES_SEARCH_RETURNED_NO_RESULTS');
             $query = $this->_helper->Query->getQueryKeyword('', $params['keyword'], $columns);
             $quoterequests = $quoterequestsDb->fetchAll($quoterequestsDb->select()->setIntegrityCheck(false)->from(array($schema => 'quoterequest'))->group($schema . '.id')->where($query ? $query : 1)->order($params['order'] . ' ' . $params['sort'])->limit($params['limit']));
         }
     }
     $quoterequests->subtotal = 0;
     $quoterequests->total = 0;
     foreach ($quoterequests as $quoterequest) {
         $quoterequests->subtotal += $quoterequest->subtotal;
         $quoterequests->total += $quoterequest->total;
         $quoterequest->subtotal = $this->_currency->toCurrency($quoterequest->subtotal);
         $quoterequest->taxes = $this->_currency->toCurrency($quoterequest->taxes);
         $quoterequest->total = $this->_currency->toCurrency($quoterequest->total);
     }
     $quoterequests->subtotal = $this->_currency->toCurrency($quoterequests->subtotal);
     $quoterequests->total = $this->_currency->toCurrency($quoterequests->total);
     return $quoterequests;
 }