/**
  * AddAction for Invoices
  *
  * @return void
  */
 public function addAction()
 {
     if ($this->getRequest()->isPost()) {
         $del = $this->getRequest()->getPost('del');
         if ($del == 'Yes') {
             $invoice["receipt_id"] = $this->getRequest()->getPost('id');
             //                Zend_Debug::dump($invoice);
             //                die();
             $model = new Finances_Model_Invoices();
             $model->save($invoice);
         }
         return $this->_helper->redirector->gotoSimple('consult', 'finances', 'finances');
     } else {
         $id = $_SESSION["production"]["id"];
         if ($id > 0) {
             $model = new Finances_Model_Receipts();
             $this->view->client = $model->fetchReceiptEntry($id);
             $this->view->invoices = $model->fetchReceiptEntries($id);
         }
     }
 }
 /**
  * inlitterAction for Receiptss
  *
  * @return void
  */
 public function inlitterAction()
 {
     if ($this->getRequest()->isPost()) {
         $del = $this->getRequest()->getPost('del');
         if ($del == 'Yes') {
             $id = $this->getRequest()->getPost('id');
             $model = new Finances_Model_Receipts();
             $model->inLitter('id = ' . (int) $id);
         }
         return $this->_helper->redirector('index');
     } else {
         $id = $this->_getParam('id', 0);
         if ($id > 0) {
             $model = new Finances_Model_Receipts();
             $this->view->receipts = $model->fetchEntry($id);
         }
     }
 }
 /**
  * AddAction for Receipt
  *
  * @return void
  */
 public function addreceiptAction()
 {
     if ($this->_request->isXmlHttpRequest()) {
         $this->_helper->viewRenderer->setNoRender(true);
         $this->_helper->layout->disableLayout();
     }
     $id = $this->_getParam('id', 10);
     $price = $this->_getParam('price', 0);
     $facturation_type = $this->_getParam('facturation_type', 32);
     //        Zend_Debug::dump($price,"facturation_type");
     //        Zend_Debug::dump($facturation_type,"facturation_type");
     //        die();
     if ($id == 0) {
         return $this->_helper->_redirector->gotoSimple('consult', 'finances', 'finances');
     }
     $model_resource_activity_has_receipt = new Finances_Model_Resourceactivityhasreceipt();
     // Comprobar que no esta añadido en el recibo
     $receipt_id = $model_resource_activity_has_receipt->fetchEntryActivityResource($id);
     if ($receipt_id != null) {
         return $this->_helper->_redirector->gotoSimple('consult', 'finances', 'finances');
     }
     // Comprobar que los campos de : tipo de facturación, precio estan rellenados
     $model_receipt = new Finances_Model_Receipts();
     $data_receipt = $model_receipt->fetchProductionHasOpenReceipt($_SESSION["production"]["id"]);
     $receipt_id = $data_receipt["id"];
     // Comprobar que no hay ningun recibo abierto en la produccion
     if (!$receipt_id) {
         // Si no lo hay introducir crear un recibo
         $receipt_id = $model_receipt->save($id);
     }
     $model_activity_resource = new Production_Model_Resource();
     $data_activity_resource["iva_type"] = $model_activity_resource->fetchIvaType($id);
     $data_activity_resource["receipts_id"] = $receipt_id;
     $data_activity_resource["resources_activities_id"] = $id;
     $data_activity_resource["price"] = (int) $price;
     $data_activity_resource["facturation_types_id"] = (int) $facturation_type;
     $data_activity_resource["quantity"] = $model_activity_resource->fetchQuantity($id);
     $data_activity_resource["final_price"] = $model_resource_activity_has_receipt->calculateFinalPrice($data_activity_resource["resources_activities_id"], $data_activity_resource["price"], $data_activity_resource["facturation_types_id"], $data_activity_resource["quantity"]);
     $data_actitity_resource["id"] = $model_resource_activity_has_receipt->save($data_activity_resource);
     $json = Zend_Json::encode($model_resource_activity_has_receipt->fetchEntry($data_actitity_resource["id"]));
     echo $json;
     //        return $this->_helper->_redirector->gotoSimple('consult', 'finances', 'finances');
 }