示例#1
0
 function Main()
 {
     $treasurySettings = new TreasurySettings();
     switch ($this->formArray["formAction"]) {
         case "reset":
             // If TreasurySettings Table doesn't exist, Create table and insert defaults from masterTables
             $treasurySettings->setPenaltyLUT($this->masterTables["penaltyLUT"]);
             $treasurySettings->setAnnualDueDate($this->masterTables["annualDueDate"]);
             $treasurySettings->setPctRPTax($this->masterTables["pctRPTax"]);
             $treasurySettings->setPctSEF($this->masterTables["pctSEF"]);
             $treasurySettings->setPctIdle($this->masterTables["pctIdle"]);
             $treasurySettings->setDiscountPercentage($this->masterTables["discountPercentage"]);
             $treasurySettings->setDiscountPeriod($this->masterTables["discountPeriod"]);
             $treasurySettings->setAdvancedDiscountPercentage($this->masterTables["advancedDiscountPercentage"]);
             $treasurySettings->setQ1AdvancedDiscountPercentage($this->masterTables["q1AdvancedDiscountPercentage"]);
             if (!$treasurySettings->tableExists()) {
                 $treasurySettings->createTable();
                 $treasurySettings->insertRecord();
             } else {
                 $treasurySettings->updateRecord();
             }
             $this->formArray["message"] = "Variables reset to default values.";
             break;
         case "save":
             if ($treasurySettings->tableExists()) {
                 ksort($this->formArray["penaltyLUT"]);
                 reset($this->formArray["penaltyLUT"]);
                 $treasurySettings->setPenaltyLUT($this->formArray["penaltyLUT"]);
                 $treasurySettings->setAnnualDueDate($this->formArray["annualDueDate"]);
                 $treasurySettings->setPctRPTax($this->formArray["pctRPTax"]);
                 $treasurySettings->setPctSEF($this->formArray["pctSEF"]);
                 $treasurySettings->setPctIdle($this->formArray["pctIdle"]);
                 $treasurySettings->setDiscountPercentage($this->formArray["discountPercentage"]);
                 $treasurySettings->setDiscountPeriod($this->formArray["discountPeriod"]);
                 $treasurySettings->setAdvancedDiscountPercentage($this->formArray["advancedDiscountPercentage"]);
                 $treasurySettings->setQ1AdvancedDiscountPercentage($this->formArray["q1AdvancedDiscountPercentage"]);
                 if ($treasurySettings->updateRecord()) {
                     $this->formArray["message"] = "Treasury Settings saved.";
                 } else {
                     $this->formArray["message"] = "Error saving. Try clicking 'Reset' to restore defaults.";
                 }
             } else {
                 $this->formArray["message"] = "Error saving. Try clicking 'Reset' to restore defaults.";
             }
             break;
         default:
             // If TreasurySettings Table doesn't exist, Create table and insert defaults from masterTables (upon installation)
             if (!$treasurySettings->tableExists()) {
                 $treasurySettings->createTable();
             }
             // If somehow no record exists in Treasury Settings, Insert a Record (unlikely to occur)
             if (!$treasurySettings->selectRecord()) {
                 $treasurySettings->setPenaltyLUT($this->masterTables["penaltyLUT"]);
                 $treasurySettings->setAnnualDueDate($this->masterTables["annualDueDate"]);
                 $treasurySettings->setPctRPTax($this->masterTables["pctRPTax"]);
                 $treasurySettings->setPctSEF($this->masterTables["pctSEF"]);
                 $treasurySettings->setPctIdle($this->masterTables["pctIdle"]);
                 $treasurySettings->setDiscountPercentage($this->masterTables["discountPercentage"]);
                 $treasurySettings->setDiscountPeriod($this->masterTables["discountPeriod"]);
                 $treasurySettings->setAdvancedDiscountPercentage($this->masterTables["advancedDiscountPercentage"]);
                 $treasurySettings->setQ1AdvancedDiscountPercentage($this->masterTables["q1AdvancedDiscountPercentage"]);
                 $treasurySettings->insertRecord();
             }
             // If somehow more than 1 record exists in Treasury Settings, delete all records and Insert Record (unlikely to occur)
             if ($treasurySettings->countRecord() > 1) {
                 $treasurySettings->deleteRecord();
                 $treasurySettings->setPenaltyLUT($this->masterTables["penaltyLUT"]);
                 $treasurySettings->setAnnualDueDate($this->masterTables["annualDueDate"]);
                 $treasurySettings->setPctRPTax($this->masterTables["pctRPTax"]);
                 $treasurySettings->setPctSEF($this->masterTables["pctSEF"]);
                 $treasurySettings->setPctIdle($this->masterTables["pctIdle"]);
                 $treasurySettings->setDiscountPercentage($this->masterTables["discountPercentage"]);
                 $treasurySettings->setDiscountPeriod($this->masterTables["discountPeriod"]);
                 $treasurySettings->setAdvancedDiscountPercentage($this->masterTables["advancedDiscountPercentage"]);
                 $treasurySettings->setQ1AdvancedDiscountPercentage($this->masterTables["q1AdvancedDiscountPercentage"]);
                 $treasurySettings->insertRecord();
             }
     }
     if ($treasurySettings->selectRecord()) {
         $this->formArray["penaltyLUT"] = $treasurySettings->getPenaltyLUT();
         $this->formArray["annualDueDate"] = $treasurySettings->getAnnualDueDate();
         $this->formArray["pctRPTax"] = $treasurySettings->getPctRPTax();
         $this->formArray["pctSEF"] = $treasurySettings->getPctSEF();
         $this->formArray["pctIdle"] = $treasurySettings->getPctIdle();
         $this->formArray["discountPercentage"] = $treasurySettings->getDiscountPercentage();
         $this->formArray["discountPeriod"] = $treasurySettings->getDiscountPeriod();
         $this->formArray["advancedDiscountPercentage"] = $treasurySettings->getAdvancedDiscountPercentage();
         $this->formArray["q1AdvancedDiscountPercentage"] = $treasurySettings->getQ1AdvancedDiscountPercentage();
     } else {
         foreach ($this->masterTables as $key => $value) {
             $this->formArray[$key] = $value;
         }
     }
     $this->showPenaltyLUTList();
     $this->setForm();
     $this->tpl->set_var("uname", $this->user["uname"]);
     $this->tpl->set_var("today", date("F j, Y"));
     $this->tpl->set_var("Session", $this->sess->url(""));
     $this->tpl->parse("templatePage", "rptsTemplate");
     $this->tpl->finish("templatePage");
     $this->tpl->p("templatePage");
 }