Exemplo n.º 1
0
 function insertRecord()
 {
     $mergedReceiptRecords = new MergedReceiptRecords();
     $condition = "WHERE ";
     // look for existing basicReceiptIDs
     $condition .= "(";
     $i = 0;
     foreach ($this->formArray["basicReceiptIDArray"] as $basicReceiptID) {
         if ($i > 0) {
             $condition .= " OR ";
         }
         $condition .= "basicReceiptIDCSV LIKE '" . $basicReceiptID . "'";
         $condition .= " OR basicReceiptIDCSV LIKE '" . $basicReceiptID . ",%'";
         $condition .= " OR basicReceiptIDCSV LIKE '%," . $basicReceiptID . ",%'";
         $condition .= " OR basicReceiptIDCSV LIKE '%," . $basicReceiptID . "'";
         $i++;
     }
     $condition .= ")";
     // look for existing sefReceiptIDs
     $condition .= " AND ";
     $condition .= "(";
     $i = 0;
     foreach ($this->formArray["sefReceiptIDArray"] as $sefReceiptID) {
         if ($i > 0) {
             $condition .= " OR ";
         }
         $condition .= "sefReceiptIDCSV LIKE '" . $sefReceiptID . "'";
         $condition .= " OR sefReceiptIDCSV LIKE '" . $sefReceiptID . ",%'";
         $condition .= " OR sefReceiptIDCSV LIKE '%," . $sefReceiptID . ",%'";
         $condition .= " OR sefReceiptIDCSV LIKE '%," . $sefReceiptID . "'";
         $i++;
     }
     $condition .= ")";
     // look for existing idleReceiptIDs
     $condition .= " AND ";
     $condition .= "(";
     $i = 0;
     foreach ($this->formArray["idleReceiptIDArray"] as $idleReceiptID) {
         if ($i > 0) {
             $condition .= " OR ";
         }
         $condition .= "idleReceiptIDCSV LIKE '" . $idleReceiptID . "'";
         $condition .= " OR idleReceiptIDCSV LIKE '" . $idleReceiptID . ",%'";
         $condition .= " OR idleReceiptIDCSV LIKE '%," . $idleReceiptID . ",%'";
         $condition .= " OR idleReceiptIDCSV LIKE '%," . $idleReceiptID . "'";
         $i++;
     }
     $condition .= ")";
     $condition .= " AND status!='cancelled'";
     if (!$mergedReceiptRecords->selectRecords($condition)) {
         $mergedReceipt = new MergedReceipt();
         $mergedReceipt->setBasicReceiptAmount($this->formArray["basicReceiptAmount"]);
         $mergedReceipt->setBasicReceiptNumber($this->formArray["basicReceiptNumber"]);
         $mergedReceipt->setBasicPreviousReceiptNumber($this->formArray["basicPreviousReceiptNumber"]);
         $mergedReceipt->setBasicPreviousReceiptDate($this->formArray["basicPreviousReceiptDate"]);
         $basicReceiptIDCSV = "";
         if (is_array($this->formArray["basicReceiptIDArray"])) {
             $basicReceiptIDCSV = implode(",", $this->formArray["basicReceiptIDArray"]);
         }
         $mergedReceipt->setBasicReceiptIDCSV($basicReceiptIDCSV);
         $mergedReceipt->setSefReceiptAmount($this->formArray["sefReceiptAmount"]);
         $mergedReceipt->setSefReceiptNumber($this->formArray["sefReceiptNumber"]);
         $mergedReceipt->setSefPreviousReceiptNumber($this->formArray["sefPreviousReceiptNumber"]);
         $mergedReceipt->setSefPreviousReceiptDate($this->formArray["sefPreviousReceiptDate"]);
         $sefReceiptIDCSV = "";
         if (is_array($this->formArray["sefReceiptIDArray"])) {
             $sefReceiptIDCSV = implode(",", $this->formArray["sefReceiptIDArray"]);
         }
         $mergedReceipt->setSefReceiptIDCSV($sefReceiptIDCSV);
         $mergedReceipt->setIdleReceiptAmount($this->formArray["idleReceiptAmount"]);
         $mergedReceipt->setIdleReceiptNumber($this->formArray["idleReceiptNumber"]);
         $mergedReceipt->setIdlePreviousReceiptNumber($this->formArray["idlePreviousReceiptNumber"]);
         $mergedReceipt->setIdlePreviousReceiptDate($this->formArray["idlePreviousReceiptDate"]);
         $idleReceiptIDCSV = "";
         if (is_array($this->formArray["idleReceiptIDArray"])) {
             $idleReceiptIDCSV = implode(",", $this->formArray["idleReceiptIDArray"]);
         }
         $mergedReceipt->setIdleReceiptIDCSV($idleReceiptIDCSV);
         $mergedReceipt->setPaymentMode($this->formArray["paymentMode"]);
         $mergedReceipt->setCheckNumber($this->formArray["checkNumber"]);
         $mergedReceipt->setDateOfCheck($this->formArray["dateOfCheck"]);
         $mergedReceipt->setDraweeBank($this->formArray["draweeBank"]);
         $mergedReceipt->setCityTreasurer($this->formArray["cityTreasurer"]);
         $mergedReceipt->setDeputyTreasurer($this->formArray["deputyTreasurer"]);
         $mergedReceipt->setReceiptDate($this->formArray["receiptDate"]);
         $mergedReceipt->setReceivedFrom($this->formArray["receivedFrom"]);
         $mergedReceipt->setReceivedFromName($this->getReceivedFromName($this->formArray["receivedFrom"]));
         $mergedReceipt->setStatus("");
         $mergedReceipt->setCreatedBy($this->userID);
         $mergedReceipt->setModifiedBy($this->userID);
         $mergedReceipt->insertRecord();
     } else {
         // update first record
         $mergedReceipt = $mergedReceiptRecords->arrayList[0];
         $mergedReceipt->setBasicReceiptAmount($this->formArray["basicReceiptAmount"]);
         $mergedReceipt->setBasicReceiptNumber($this->formArray["basicReceiptNumber"]);
         $mergedReceipt->setBasicPreviousReceiptNumber($this->formArray["basicPreviousReceiptNumber"]);
         $mergedReceipt->setBasicPreviousReceiptDate($this->formArray["basicPreviousReceiptDate"]);
         $basicReceiptIDCSV = "";
         if (is_array($this->formArray["basicReceiptIDArray"])) {
             $basicReceiptIDCSV = implode(",", $this->formArray["basicReceiptIDArray"]);
         }
         $mergedReceipt->setBasicReceiptIDCSV($basicReceiptIDCSV);
         $mergedReceipt->setSefReceiptAmount($this->formArray["sefReceiptAmount"]);
         $mergedReceipt->setSefReceiptNumber($this->formArray["sefReceiptNumber"]);
         $mergedReceipt->setSefPreviousReceiptNumber($this->formArray["sefPreviousReceiptNumber"]);
         $mergedReceipt->setSefPreviousReceiptDate($this->formArray["sefPreviousReceiptDate"]);
         $sefReceiptIDCSV = "";
         if (is_array($this->formArray["sefReceiptIDArray"])) {
             $sefReceiptIDCSV = implode(",", $this->formArray["sefReceiptIDArray"]);
         }
         $mergedReceipt->setSefReceiptIDCSV($sefReceiptIDCSV);
         $mergedReceipt->setIdleReceiptAmount($this->formArray["idleReceiptAmount"]);
         $mergedReceipt->setIdleReceiptNumber($this->formArray["idleReceiptNumber"]);
         $mergedReceipt->setIdlePreviousReceiptNumber($this->formArray["idlePreviousReceiptNumber"]);
         $mergedReceipt->setIdlePreviousReceiptDate($this->formArray["idlePreviousReceiptDate"]);
         $idleReceiptIDCSV = "";
         if (is_array($this->formArray["idleReceiptIDArray"])) {
             $idleReceiptIDCSV = implode(",", $this->formArray["idleReceiptIDArray"]);
         }
         $mergedReceipt->setIdleReceiptIDCSV($idleReceiptIDCSV);
         $mergedReceipt->setPaymentMode($this->formArray["paymentMode"]);
         $mergedReceipt->setCheckNumber($this->formArray["checkNumber"]);
         $mergedReceipt->setDateOfCheck($this->formArray["dateOfCheck"]);
         $mergedReceipt->setDraweeBank($this->formArray["draweeBank"]);
         $mergedReceipt->setCityTreasurer($this->formArray["cityTreasurer"]);
         $mergedReceipt->setDeputyTreasurer($this->formArray["deputyTreasurer"]);
         $mergedReceipt->setReceiptDate($this->formArray["receiptDate"]);
         $mergedReceipt->setReceivedFrom($this->formArray["receivedFrom"]);
         $mergedReceipt->setReceivedFromName($this->getReceivedFromName($this->formArray["receivedFrom"]));
         $mergedReceipt->setStatus("");
         $mergedReceipt->setCreatedBy($this->userID);
         $mergedReceipt->setModifiedBy($this->userID);
         $mergedReceipt->updateRecord();
     }
 }