Location: PHPKode > projects > CoopWorks Farmers Association Management > CoopWorks 3.1/IN_Receipts_Confirm.php
<?php
//Aworks.org/licence.html.  
// Produced by Webdiscount Technologies(Kenya) under Contract 
// No. KSL/CONSULT.GEN/1 with the The Kenya National Federation of Agricultural Producers(KENFAP) and in collaboration with Food and Agriculture Organization 
// of the United Nations (FAO),  Agriculturathe Ministry of 
// Co-operative Development and Marketing (Kenya) and piloted at Wamunyu Dairy Cooperative Society(Kenya) and Ololaiser Dairy Farmers Cooperative Society(Kenya).

//Include Common Files @1-CCAFBE82
define("RelativePath", ".");
define("PathToCurrentPage", "/");
define("FileName", "IN_Receipts_Confirm.php");
include(RelativePath . "/Common.php");
include(RelativePath . "/Template.php");
include(RelativePath . "/Sorter.php");
include(RelativePath . "/Navigator.php");
include(RelativePath . "/SM_SubMenuControl.php");

//End Include Common Files

class clsRecordinreceiptsSearch { //inreceiptsSearch Class @6-120BE2AF

//Variables @6-D6FF3E86

    // Public variables
    var $ComponentType = "Record";
    var $ComponentName;
    var $Parent;
    var $HTMLFormAction;
    var $PressedButton;
    var $Errors;
    var $ErrorBlock;
    var $FormSubmitted;
    var $FormEnctype;
    var $Visible;
    var $IsEmpty;

    var $CCSEvents = "";
    var $CCSEventResult;

    var $RelativePath = "";

    var $InsertAllowed = false;
    var $UpdateAllowed = false;
    var $DeleteAllowed = false;
    var $ReadAllowed   = false;
    var $EditMode      = false;
    var $ds;
    var $DataSource;
    var $ValidatingControls;
    var $Controls;
    var $Attributes;

    // Class variables
//End Variables

//Class_Initialize Event @6-D0F4D907
    function clsRecordinreceiptsSearch($RelativePath, & $Parent)
    {

        global $FileName;
        global $CCSLocales;
        global $DefaultDateFormat;
        $this->Visible = true;
        $this->Parent = & $Parent;
        $this->RelativePath = $RelativePath;
        $this->Errors = new clsErrors();
        $this->ErrorBlock = "Record inreceiptsSearch/Error";
        $this->ReadAllowed = true;
        if($this->Visible)
        {
            $this->ComponentName = "inreceiptsSearch";
            $this->Attributes = new clsAttributes($this->ComponentName . ":");
            $CCSForm = split(":", CCGetFromGet("ccsForm", ""), 2);
            if(sizeof($CCSForm) == 1)
                $CCSForm[1] = "";
            list($FormName, $FormMethod) = $CCSForm;
            $this->FormEnctype = "application/x-www-form-urlencoded";
            $this->FormSubmitted = ($FormName == $this->ComponentName);
            $Method = $this->FormSubmitted ? ccsPost : ccsGet;
            $this->s_TranDate = & new clsControl(ccsTextBox, "s_TranDate", "s_TranDate", ccsDate, array("mm", "/", "dd", "/", "yyyy"), CCGetRequestParam("s_TranDate", $Method, NULL), $this);
            $this->s_Site = & new clsControl(ccsListBox, "s_Site", "s_Site", ccsText, "", CCGetRequestParam("s_Site", $Method, NULL), $this);
            $this->s_Site->DSType = dsTable;
            $this->s_Site->DataSource = new clsDBCoopWorksConn();
            $this->s_Site->ds = & $this->s_Site->DataSource;
            $this->s_Site->DataSource->SQL = "SELECT * \n" .
"FROM instore {SQL_Where} {SQL_OrderBy}";
            list($this->s_Site->BoundColumn, $this->s_Site->TextColumn, $this->s_Site->DBFormat) = array("STOREID", "Descr", "");
            $this->Button_DoSearch = & new clsButton("Button_DoSearch", $Method, $this);
            $this->DatePicker_s_TranDate1 = & new clsDatePicker("DatePicker_s_TranDate1", "inreceiptsSearch", "s_TranDate", $this);
            if(!$this->FormSubmitted) {
                if(!is_array($this->s_TranDate->Value) && !strlen($this->s_TranDate->Value) && $this->s_TranDate->Value !== false)
                    $this->s_TranDate->SetValue(time());
            }
        }
    }
//End Class_Initialize Event

//Validate Method @6-2736A5BA
    function Validate()
    {
        global $CCSLocales;
        $Validation = true;
        $Where = "";
        $Validation = ($this->s_TranDate->Validate() && $Validation);
        $Validation = ($this->s_Site->Validate() && $Validation);
        $this->CCSEventResult = CCGetEvent($this->CCSEvents, "OnValidate", $this);
        $Validation =  $Validation && ($this->s_TranDate->Errors->Count() == 0);
        $Validation =  $Validation && ($this->s_Site->Errors->Count() == 0);
        return (($this->Errors->Count() == 0) && $Validation);
    }
//End Validate Method

//CheckErrors Method @6-AD712E70
    function CheckErrors()
    {
        $errors = false;
        $errors = ($errors || $this->s_TranDate->Errors->Count());
        $errors = ($errors || $this->s_Site->Errors->Count());
        $errors = ($errors || $this->DatePicker_s_TranDate1->Errors->Count());
        $errors = ($errors || $this->Errors->Count());
        return $errors;
    }
//End CheckErrors Method

//MasterDetail @6-ED598703
function SetPrimaryKeys($keyArray)
{
    $this->PrimaryKeys = $keyArray;
}
function GetPrimaryKeys()
{
    return $this->PrimaryKeys;
}
function GetPrimaryKey($keyName)
{
    return $this->PrimaryKeys[$keyName];
}
//End MasterDetail

//Operation Method @6-D5AB8686
    function Operation()
    {
        if(!$this->Visible)
            return;

        global $Redirect;
        global $FileName;

        if(!$this->FormSubmitted) {
            return;
        }

        if($this->FormSubmitted) {
            $this->PressedButton = "Button_DoSearch";
            if($this->Button_DoSearch->Pressed) {
                $this->PressedButton = "Button_DoSearch";
            }
        }
        $Redirect = "IN_Receipts_Confirm.php";
        if($this->Validate()) {
            if($this->PressedButton == "Button_DoSearch") {
                $Redirect = "IN_Receipts_Confirm.php" . "?" . CCMergeQueryStrings(CCGetQueryString("Form", array("Button_DoSearch", "Button_DoSearch_x", "Button_DoSearch_y")));
                if(!CCGetEvent($this->Button_DoSearch->CCSEvents, "OnClick", $this->Button_DoSearch)) {
                    $Redirect = "";
                }
            }
        } else {
            $Redirect = "";
        }
    }
//End Operation Method

//Show Method @6-966B5C27
    function Show()
    {
        global $CCSUseAmp;
        global $Tpl;
        global $FileName;
        global $CCSLocales;
        $Error = "";

        if(!$this->Visible)
            return;

        $this->CCSEventResult = CCGetEvent($this->CCSEvents, "BeforeSelect", $this);

        $this->s_Site->Prepare();

        $RecordBlock = "Record " . $this->ComponentName;
        $ParentPath = $Tpl->block_path;
        $Tpl->block_path = $ParentPath . "/" . $RecordBlock;
        $this->EditMode = $this->EditMode && $this->ReadAllowed;
        if (!$this->FormSubmitted) {
        }

        if($this->FormSubmitted || $this->CheckErrors()) {
            $Error = "";
            $Error = ComposeStrings($Error, $this->s_TranDate->Errors->ToString());
            $Error = ComposeStrings($Error, $this->s_Site->Errors->ToString());
            $Error = ComposeStrings($Error, $this->DatePicker_s_TranDate1->Errors->ToString());
            $Error = ComposeStrings($Error, $this->Errors->ToString());
            $Tpl->SetVar("Error", $Error);
            $Tpl->Parse("Error", false);
        }
        $CCSForm = $this->EditMode ? $this->ComponentName . ":" . "Edit" : $this->ComponentName;
        $this->HTMLFormAction = $FileName . "?" . CCAddParam(CCGetQueryString("QueryString", ""), "ccsForm", $CCSForm);
        $Tpl->SetVar("Action", !$CCSUseAmp ? $this->HTMLFormAction : str_replace("&", "&amp;", $this->HTMLFormAction));
        $Tpl->SetVar("HTMLFormName", $this->ComponentName);
        $Tpl->SetVar("HTMLFormEnctype", $this->FormEnctype);

        $this->CCSEventResult = CCGetEvent($this->CCSEvents, "BeforeShow", $this);
        $this->Attributes->Show();
        if(!$this->Visible) {
            $Tpl->block_path = $ParentPath;
            return;
        }

        $this->s_TranDate->Show();
        $this->s_Site->Show();
        $this->Button_DoSearch->Show();
        $this->DatePicker_s_TranDate1->Show();
        $Tpl->parse();
        $Tpl->block_path = $ParentPath;
    }
//End Show Method

} //End inreceiptsSearch Class @6-FCB6E20C

class clsEditableGridinreceipts { //inreceipts Class @2-5E3E6D79

//Variables @2-C148AA66

    // Public variables
    var $ComponentType = "EditableGrid";
    var $ComponentName;
    var $HTMLFormAction;
    var $PressedButton;
    var $Errors;
    var $ErrorBlock;
    var $FormSubmitted;
    var $FormParameters;
    var $FormState;
    var $FormEnctype;
    var $CachedColumns;
    var $TotalRows;
    var $UpdatedRows;
    var $EmptyRows;
    var $Visible;
    var $RowsErrors;
    var $ds;
    var $DataSource;
    var $PageSize;
    var $IsEmpty;
    var $SorterName = "";
    var $SorterDirection = "";
    var $PageNumber;
    var $ControlsVisible = array();

    var $CCSEvents = "";
    var $CCSEventResult;

    var $RelativePath = "";

    var $InsertAllowed = false;
    var $UpdateAllowed = false;
    var $DeleteAllowed = false;
    var $ReadAllowed   = false;
    var $EditMode;
    var $ValidatingControls;
    var $Controls;
    var $ControlsErrors;
    var $RowNumber;
    var $Attributes;
    var $PrimaryKeys;

    // Class variables
    var $Sorter1;
    var $Sorter2;
    var $Sorter3;
    var $Sorter4;
    var $Sorter5;
    var $Sorter6;
    var $Sorter7;
//End Variables

//Class_Initialize Event @2-11466FBD
    function clsEditableGridinreceipts($RelativePath, & $Parent)
    {

        global $FileName;
        global $CCSLocales;
        global $DefaultDateFormat;
        $this->Visible = true;
        $this->Parent = & $Parent;
        $this->RelativePath = $RelativePath;
        $this->Errors = new clsErrors();
        $this->ErrorBlock = "EditableGrid inreceipts/Error";
        $this->ControlsErrors = array();
        $this->ComponentName = "inreceipts";
        $this->Attributes = new clsAttributes($this->ComponentName . ":");
        $this->CachedColumns["recid"][0] = "recid";
        $this->DataSource = new clsinreceiptsDataSource($this);
        $this->ds = & $this->DataSource;
        $this->PageSize = CCGetParam($this->ComponentName . "PageSize", "");
        if(!is_numeric($this->PageSize) || !strlen($this->PageSize))
            $this->PageSize = 100;
        else
            $this->PageSize = intval($this->PageSize);
        if ($this->PageSize > 100)
            $this->PageSize = 100;
        if($this->PageSize == 0)
            $this->Errors->addError("<p>Form: EditableGrid " . $this->ComponentName . "<br>Error: (CCS06) Invalid page size.</p>");
        $this->PageNumber = intval(CCGetParam($this->ComponentName . "Page", 1));
        if ($this->PageNumber <= 0) $this->PageNumber = 1;

        $this->EmptyRows = 0;
        $this->UpdateAllowed = true;
        $this->ReadAllowed = true;
        if(!$this->Visible) return;

        $CCSForm = CCGetFromGet("ccsForm", "");
        $this->FormEnctype = "application/x-www-form-urlencoded";
        $this->FormSubmitted = ($CCSForm == $this->ComponentName);
        if($this->FormSubmitted) {
            $this->FormState = CCGetFromPost("FormState", "");
            $this->SetFormState($this->FormState);
        } else {
            $this->FormState = "";
        }
        $Method = $this->FormSubmitted ? ccsPost : ccsGet;

        $this->SorterName = CCGetParam("inreceiptsOrder", "");
        $this->SorterDirection = CCGetParam("inreceiptsDir", "");

        $this->RceptNbr = & new clsControl(ccsLabel, "RceptNbr", "Rcept Nbr", ccsText, "", NULL, $this);
        $this->recid = & new clsControl(ccsHidden, "recid", "Recid", ccsInteger, "", NULL, $this);
        $this->recid->Required = true;
        $this->TranDate = & new clsControl(ccsLabel, "TranDate", "Tran Date", ccsDate, $DefaultDateFormat, NULL, $this);
        $this->InvtId = & new clsControl(ccsLabel, "InvtId", "Invt Id", ccsText, "", NULL, $this);
        $this->Site = & new clsControl(ccsLabel, "Site", "Site", ccsText, "", NULL, $this);
        $this->Qty = & new clsControl(ccsLabel, "Qty", "Qty", ccsFloat, "", NULL, $this);
        $this->UnitCost = & new clsControl(ccsLabel, "UnitCost", "Unit Cost", ccsFloat, "", NULL, $this);
        $this->StkQtyFactor = & new clsControl(ccsLabel, "StkQtyFactor", "Stk Qty Factor", ccsFloat, "", NULL, $this);
        $this->TranCost = & new clsControl(ccsLabel, "TranCost", "Tran Cost", ccsFloat, "", NULL, $this);
        $this->Confirmed = & new clsControl(ccsCheckBox, "Confirmed", "Confirmed", ccsInteger, "", NULL, $this);
        $this->Confirmed->CheckedValue = $this->Confirmed->GetParsedValue(1);
        $this->Confirmed->UncheckedValue = $this->Confirmed->GetParsedValue(0);
        $this->Navigator = & new clsNavigator($this->ComponentName, "Navigator", $FileName, 10, tpCentered, $this);
        $this->Navigator->PageSizes = array("1", "5", "10", "25", "50");
        $this->Button_Submit = & new clsButton("Button_Submit", $Method, $this);
        $this->Cancel = & new clsButton("Cancel", $Method, $this);
        $this->Sorter1 = & new clsSorter($this->ComponentName, "Sorter1", $FileName, $this);
        $this->Sorter2 = & new clsSorter($this->ComponentName, "Sorter2", $FileName, $this);
        $this->Sorter3 = & new clsSorter($this->ComponentName, "Sorter3", $FileName, $this);
        $this->Sorter4 = & new clsSorter($this->ComponentName, "Sorter4", $FileName, $this);
        $this->Sorter5 = & new clsSorter($this->ComponentName, "Sorter5", $FileName, $this);
        $this->Sorter6 = & new clsSorter($this->ComponentName, "Sorter6", $FileName, $this);
        $this->Sorter7 = & new clsSorter($this->ComponentName, "Sorter7", $FileName, $this);
    }
//End Class_Initialize Event

//Initialize Method @2-83030836
    function Initialize()
    {
        if(!$this->Visible) return;

        $this->DataSource->PageSize = & $this->PageSize;
        $this->DataSource->AbsolutePage = & $this->PageNumber;
        $this->DataSource->SetOrder($this->SorterName, $this->SorterDirection);

        $this->DataSource->Parameters["urlConfirmed"] = CCGetFromGet("Confirmed", NULL);
        $this->DataSource->Parameters["urls_TranDate"] = CCGetFromGet("s_TranDate", NULL);
        $this->DataSource->Parameters["urls_Site"] = CCGetFromGet("s_Site", NULL);
    }
//End Initialize Method

//SetPrimaryKeys Method @2-EBC3F86C
    function SetPrimaryKeys($PrimaryKeys) {
        $this->PrimaryKeys = $PrimaryKeys;
        return $this->PrimaryKeys;
    }
//End SetPrimaryKeys Method

//GetPrimaryKeys Method @2-74F9A772
    function GetPrimaryKeys() {
        return $this->PrimaryKeys;
    }
//End GetPrimaryKeys Method

//GetFormParameters Method @2-F679FD01
    function GetFormParameters()
    {
        for($RowNumber = 1; $RowNumber <= $this->TotalRows; $RowNumber++)
        {
            $this->FormParameters["recid"][$RowNumber] = CCGetFromPost("recid_" . $RowNumber, NULL);
            $this->FormParameters["Confirmed"][$RowNumber] = CCGetFromPost("Confirmed_" . $RowNumber, NULL);
        }
    }
//End GetFormParameters Method

//Validate Method @2-23AE4DF2
    function Validate()
    {
        $Validation = true;
        $this->CCSEventResult = CCGetEvent($this->CCSEvents, "OnValidate", $this);

        for($this->RowNumber = 1; $this->RowNumber <= $this->TotalRows; $this->RowNumber++)
        {
            $this->DataSource->CachedColumns["recid"] = $this->CachedColumns["recid"][$this->RowNumber];
            $this->DataSource->CurrentRow = $this->RowNumber;
            $this->recid->SetText($this->FormParameters["recid"][$this->RowNumber], $this->RowNumber);
            $this->Confirmed->SetText($this->FormParameters["Confirmed"][$this->RowNumber], $this->RowNumber);
            if ($this->UpdatedRows >= $this->RowNumber) {
                $Validation = ($this->ValidateRow($this->RowNumber) && $Validation);
            }
            else if($this->CheckInsert())
            {
                $Validation = ($this->ValidateRow() && $Validation);
            }
        }
        return (($this->Errors->Count() == 0) && $Validation);
    }
//End Validate Method

//ValidateRow Method @2-A56C3CA2
    function ValidateRow()
    {
        global $CCSLocales;
        $this->recid->Validate();
        $this->Confirmed->Validate();
        $this->RowErrors = new clsErrors();
        $this->CCSEventResult = CCGetEvent($this->CCSEvents, "OnValidateRow", $this);
        $errors = "";
        $errors = ComposeStrings($errors, $this->recid->Errors->ToString());
        $errors = ComposeStrings($errors, $this->Confirmed->Errors->ToString());
        $this->recid->Errors->Clear();
        $this->Confirmed->Errors->Clear();
        $errors = ComposeStrings($errors, $this->RowErrors->ToString());
        $this->RowsErrors[$this->RowNumber] = $errors;
        return $errors != "" ? 0 : 1;
    }
//End ValidateRow Method

//CheckInsert Method @2-7A0C4FD4
    function CheckInsert()
    {
        $filed = false;
        $filed = ($filed || (is_array($this->FormParameters["recid"][$this->RowNumber]) && count($this->FormParameters["recid"][$this->RowNumber])) || strlen($this->FormParameters["recid"][$this->RowNumber]));
        $filed = ($filed || (is_array($this->FormParameters["Confirmed"][$this->RowNumber]) && count($this->FormParameters["Confirmed"][$this->RowNumber])) || strlen($this->FormParameters["Confirmed"][$this->RowNumber]));
        return $filed;
    }
//End CheckInsert Method

//CheckErrors Method @2-F5A3B433
    function CheckErrors()
    {
        $errors = false;
        $errors = ($errors || $this->Errors->Count());
        $errors = ($errors || $this->DataSource->Errors->Count());
        return $errors;
    }
//End CheckErrors Method

//Operation Method @2-6B923CC2
    function Operation()
    {
        if(!$this->Visible)
            return;

        global $Redirect;
        global $FileName;

        $this->DataSource->Prepare();
        if(!$this->FormSubmitted)
            return;

        $this->GetFormParameters();
        $this->PressedButton = "Button_Submit";
        if($this->Button_Submit->Pressed) {
            $this->PressedButton = "Button_Submit";
        } else if($this->Cancel->Pressed) {
            $this->PressedButton = "Cancel";
        }

        $Redirect = $FileName . "?" . CCGetQueryString("QueryString", array("ccsForm"));
        if($this->PressedButton == "Button_Submit") {
            if(!CCGetEvent($this->Button_Submit->CCSEvents, "OnClick", $this->Button_Submit) || !$this->UpdateGrid()) {
                $Redirect = "";
            }
        } else if($this->PressedButton == "Cancel") {
            if(!CCGetEvent($this->Cancel->CCSEvents, "OnClick", $this->Cancel)) {
                $Redirect = "";
            }
        } else {
            $Redirect = "";
        }
        if ($Redirect)
            $this->DataSource->close();
    }
//End Operation Method

//UpdateGrid Method @2-EDA8AD28
    function UpdateGrid()
    {
        $this->CCSEventResult = CCGetEvent($this->CCSEvents, "BeforeSubmit", $this);
        if(!$this->Validate()) return;
        $Validation = true;
        for($this->RowNumber = 1; $this->RowNumber <= $this->TotalRows; $this->RowNumber++)
        {
            $this->DataSource->CachedColumns["recid"] = $this->CachedColumns["recid"][$this->RowNumber];
            $this->DataSource->CurrentRow = $this->RowNumber;
            $this->recid->SetText($this->FormParameters["recid"][$this->RowNumber], $this->RowNumber);
            $this->Confirmed->SetText($this->FormParameters["Confirmed"][$this->RowNumber], $this->RowNumber);
            if ($this->UpdatedRows >= $this->RowNumber) {
                if($this->UpdateAllowed) { $Validation = ($this->UpdateRow() && $Validation); }
            }
            else if($this->CheckInsert() && $this->InsertAllowed)
            {
                $Validation = ($Validation && $this->InsertRow());
            }
        }
        $this->CCSEventResult = CCGetEvent($this->CCSEvents, "AfterSubmit", $this);
        if ($this->Errors->Count() == 0 && $Validation){
            $this->DataSource->close();
            return true;
        }
        return false;
    }
//End UpdateGrid Method

//UpdateRow Method @2-34F9B04F
    function UpdateRow()
    {
        if(!$this->UpdateAllowed) return false;
        $this->DataSource->recid->SetValue($this->recid->GetValue(true));
        $this->DataSource->Confirmed->SetValue($this->Confirmed->GetValue(true));
        $this->DataSource->Update();
        $errors = "";
        if($this->DataSource->Errors->Count() > 0) {
            $errors = $this->DataSource->Errors->ToString();
            $this->RowsErrors[$this->RowNumber] = $errors;
            $this->DataSource->Errors->Clear();
        }
        return (($this->Errors->Count() == 0) && !strlen($errors));
    }
//End UpdateRow Method

//FormScript Method @2-0299F251
    function FormScript($TotalRows)
    {
        $script = "";
        $script .= "\n<script language=\"JavaScript\" type=\"text/javascript\">\n<!--\n";
        $script .= "var inreceiptsElements;\n";
        $script .= "var inreceiptsEmptyRows = 0;\n";
        $script .= "var " . $this->ComponentName . "recidID = 0;\n";
        $script .= "var " . $this->ComponentName . "ConfirmedID = 1;\n";
        $script .= "\nfunction initinreceiptsElements() {\n";
        $script .= "\tvar ED = document.forms[\"inreceipts\"];\n";
        $script .= "\tinreceiptsElements = new Array (\n";
        for($i = 1; $i <= $TotalRows; $i++) {
            $script .= "\t\tnew Array(" . "ED.recid_" . $i . ", " . "ED.Confirmed_" . $i . ")";
            if($i != $TotalRows) $script .= ",\n";
        }
        $script .= ");\n";
        $script .= "}\n";
        $script .= "\n//-->\n</script>";
        return $script;
    }
//End FormScript Method

//SetFormState Method @2-6BBEAF21
    function SetFormState($FormState)
    {
        if(strlen($FormState)) {
            $FormState = str_replace("\\\\", "\\" . ord("\\"), $FormState);
            $FormState = str_replace("\\;", "\\" . ord(";"), $FormState);
            $pieces = explode(";", $FormState);
            $this->UpdatedRows = $pieces[0];
            $this->EmptyRows   = $pieces[1];
            $this->TotalRows = $this->UpdatedRows + $this->EmptyRows;
            $RowNumber = 0;
            for($i = 2; $i < sizeof($pieces); $i = $i + 1)  {
                $piece = $pieces[$i + 0];
                $piece = str_replace("\\" . ord("\\"), "\\", $piece);
                $piece = str_replace("\\" . ord(";"), ";", $piece);
                $this->CachedColumns["recid"][$RowNumber] = $piece;
                $RowNumber++;
            }

            if(!$RowNumber) { $RowNumber = 1; }
            for($i = 1; $i <= $this->EmptyRows; $i++) {
                $this->CachedColumns["recid"][$RowNumber] = "";
                $RowNumber++;
            }
        }
    }
//End SetFormState Method

//GetFormState Method @2-6D0F1130
    function GetFormState($NonEmptyRows)
    {
        if(!$this->FormSubmitted) {
            $this->FormState  = $NonEmptyRows . ";";
            $this->FormState .= $this->InsertAllowed ? $this->EmptyRows : "0";
            if($NonEmptyRows) {
                for($i = 0; $i <= $NonEmptyRows; $i++) {
                    $this->FormState .= ";" . str_replace(";", "\\;", str_replace("\\", "\\\\", $this->CachedColumns["recid"][$i]));
                }
            }
        }
        return $this->FormState;
    }
//End GetFormState Method

//Show Method @2-80AE2811
    function Show()
    {
        global $Tpl;
        global $FileName;
        global $CCSLocales;
        global $CCSUseAmp;
        $Error = "";

        if(!$this->Visible) { return; }

        $this->CCSEventResult = CCGetEvent($this->CCSEvents, "BeforeSelect", $this);


        $this->DataSource->open();
        $is_next_record = ($this->ReadAllowed && $this->DataSource->next_record());
        $this->IsEmpty = ! $is_next_record;

        $this->CCSEventResult = CCGetEvent($this->CCSEvents, "BeforeShow", $this);
        if(!$this->Visible) { return; }

        $this->Attributes->Show();
        $this->Button_Submit->Visible = $this->Button_Submit->Visible && ($this->InsertAllowed || $this->UpdateAllowed || $this->DeleteAllowed);
        $ParentPath = $Tpl->block_path;
        $EditableGridPath = $ParentPath . "/EditableGrid " . $this->ComponentName;
        $EditableGridRowPath = $ParentPath . "/EditableGrid " . $this->ComponentName . "/Row";
        $Tpl->block_path = $EditableGridRowPath;
        $this->RowNumber = 0;
        $NonEmptyRows = 0;
        $EmptyRowsLeft = $this->EmptyRows;
        $this->ControlsVisible["RceptNbr"] = $this->RceptNbr->Visible;
        $this->ControlsVisible["recid"] = $this->recid->Visible;
        $this->ControlsVisible["TranDate"] = $this->TranDate->Visible;
        $this->ControlsVisible["InvtId"] = $this->InvtId->Visible;
        $this->ControlsVisible["Site"] = $this->Site->Visible;
        $this->ControlsVisible["Qty"] = $this->Qty->Visible;
        $this->ControlsVisible["UnitCost"] = $this->UnitCost->Visible;
        $this->ControlsVisible["StkQtyFactor"] = $this->StkQtyFactor->Visible;
        $this->ControlsVisible["TranCost"] = $this->TranCost->Visible;
        $this->ControlsVisible["Confirmed"] = $this->Confirmed->Visible;
        if ($is_next_record || ($EmptyRowsLeft && $this->InsertAllowed)) {
            do {
                $this->RowNumber++;
                if($is_next_record) {
                    $NonEmptyRows++;
                    $this->DataSource->SetValues();
                }
                if (!($this->FormSubmitted) && $is_next_record) {
                    $this->CachedColumns["recid"][$this->RowNumber] = $this->DataSource->CachedColumns["recid"];
                    $this->RceptNbr->SetValue($this->DataSource->RceptNbr->GetValue());
                    $this->recid->SetValue($this->DataSource->recid->GetValue());
                    $this->TranDate->SetValue($this->DataSource->TranDate->GetValue());
                    $this->InvtId->SetValue($this->DataSource->InvtId->GetValue());
                    $this->Site->SetValue($this->DataSource->Site->GetValue());
                    $this->Qty->SetValue($this->DataSource->Qty->GetValue());
                    $this->UnitCost->SetValue($this->DataSource->UnitCost->GetValue());
                    $this->StkQtyFactor->SetValue($this->DataSource->StkQtyFactor->GetValue());
                    $this->TranCost->SetValue($this->DataSource->TranCost->GetValue());
                    $this->Confirmed->SetValue($this->DataSource->Confirmed->GetValue());
                } elseif ($this->FormSubmitted && $is_next_record) {
                    $this->RceptNbr->SetText("");
                    $this->TranDate->SetText("");
                    $this->InvtId->SetText("");
                    $this->Site->SetText("");
                    $this->Qty->SetText("");
                    $this->UnitCost->SetText("");
                    $this->StkQtyFactor->SetText("");
                    $this->TranCost->SetText("");
                    $this->RceptNbr->SetValue($this->DataSource->RceptNbr->GetValue());
                    $this->TranDate->SetValue($this->DataSource->TranDate->GetValue());
                    $this->InvtId->SetValue($this->DataSource->InvtId->GetValue());
                    $this->Site->SetValue($this->DataSource->Site->GetValue());
                    $this->Qty->SetValue($this->DataSource->Qty->GetValue());
                    $this->UnitCost->SetValue($this->DataSource->UnitCost->GetValue());
                    $this->StkQtyFactor->SetValue($this->DataSource->StkQtyFactor->GetValue());
                    $this->TranCost->SetValue($this->DataSource->TranCost->GetValue());
                    $this->recid->SetText($this->FormParameters["recid"][$this->RowNumber], $this->RowNumber);
                    $this->Confirmed->SetText($this->FormParameters["Confirmed"][$this->RowNumber], $this->RowNumber);
                } elseif (!$this->FormSubmitted) {
                    $this->CachedColumns["recid"][$this->RowNumber] = "";
                    $this->RceptNbr->SetText("");
                    $this->recid->SetText("");
                    $this->TranDate->SetText("");
                    $this->InvtId->SetText("");
                    $this->Site->SetText("");
                    $this->Qty->SetText("");
                    $this->UnitCost->SetText("");
                    $this->StkQtyFactor->SetText("");
                    $this->TranCost->SetText("");
                    $this->Confirmed->SetValue(true);
                } else {
                    $this->RceptNbr->SetText("");
                    $this->TranDate->SetText("");
                    $this->InvtId->SetText("");
                    $this->Site->SetText("");
                    $this->Qty->SetText("");
                    $this->UnitCost->SetText("");
                    $this->StkQtyFactor->SetText("");
                    $this->TranCost->SetText("");
                    $this->recid->SetText($this->FormParameters["recid"][$this->RowNumber], $this->RowNumber);
                    $this->Confirmed->SetText($this->FormParameters["Confirmed"][$this->RowNumber], $this->RowNumber);
                }
                $this->Attributes->SetValue("rowNumber", $this->RowNumber);
                $this->CCSEventResult = CCGetEvent($this->CCSEvents, "BeforeShowRow", $this);
                $this->Attributes->Show();
                $this->RceptNbr->Show($this->RowNumber);
                $this->recid->Show($this->RowNumber);
                $this->TranDate->Show($this->RowNumber);
                $this->InvtId->Show($this->RowNumber);
                $this->Site->Show($this->RowNumber);
                $this->Qty->Show($this->RowNumber);
                $this->UnitCost->Show($this->RowNumber);
                $this->StkQtyFactor->Show($this->RowNumber);
                $this->TranCost->Show($this->RowNumber);
                $this->Confirmed->Show($this->RowNumber);
                if (isset($this->RowsErrors[$this->RowNumber]) && ($this->RowsErrors[$this->RowNumber] != "")) {
                    $Tpl->setblockvar("RowError", "");
                    $Tpl->setvar("Error", $this->RowsErrors[$this->RowNumber]);
                    $this->Attributes->Show();
                    $Tpl->parse("RowError", false);
                } else {
                    $Tpl->setblockvar("RowError", "");
                }
                $Tpl->setvar("FormScript", $this->FormScript($this->RowNumber));
                $Tpl->parse();
                if ($is_next_record) {
                    if ($this->FormSubmitted) {
                        $is_next_record = $this->RowNumber < $this->UpdatedRows;
                        if (($this->DataSource->CachedColumns["recid"] == $this->CachedColumns["recid"][$this->RowNumber])) {
                            if ($this->ReadAllowed) $this->DataSource->next_record();
                        }
                    }else{
                        $is_next_record = ($this->RowNumber < $this->PageSize) &&  $this->ReadAllowed && $this->DataSource->next_record();
                    }
                } else { 
                    $EmptyRowsLeft--;
                }
            } while($is_next_record || ($EmptyRowsLeft && $this->InsertAllowed));
        } else {
            $Tpl->block_path = $EditableGridPath;
            $this->Attributes->Show();
            $Tpl->parse("NoRecords", false);
        }

        $Tpl->block_path = $EditableGridPath;
        $this->Navigator->PageNumber = $this->DataSource->AbsolutePage;
        $this->Navigator->PageSize = $this->PageSize;
        if ($this->DataSource->RecordsCount == "CCS not counted")
            $this->Navigator->TotalPages = $this->DataSource->AbsolutePage + ($this->DataSource->next_record() ? 1 : 0);
        else
            $this->Navigator->TotalPages = $this->DataSource->PageCount();
        if ($this->Navigator->TotalPages <= 1) {
            $this->Navigator->Visible = false;
        }
        $this->Navigator->Show();
        $this->Button_Submit->Show();
        $this->Cancel->Show();
        $this->Sorter1->Show();
        $this->Sorter2->Show();
        $this->Sorter3->Show();
        $this->Sorter4->Show();
        $this->Sorter5->Show();
        $this->Sorter6->Show();
        $this->Sorter7->Show();

        if($this->CheckErrors()) {
            $Error = ComposeStrings($Error, $this->Errors->ToString());
            $Error = ComposeStrings($Error, $this->DataSource->Errors->ToString());
            $Tpl->SetVar("Error", $Error);
            $Tpl->Parse("Error", false);
        }
        $CCSForm = $this->ComponentName;
        $this->HTMLFormAction = $FileName . "?" . CCAddParam(CCGetQueryString("QueryString", ""), "ccsForm", $CCSForm);
        $Tpl->SetVar("Action", !$CCSUseAmp ? $this->HTMLFormAction : str_replace("&", "&amp;", $this->HTMLFormAction));
        $Tpl->SetVar("HTMLFormName", $this->ComponentName);
        $Tpl->SetVar("HTMLFormEnctype", $this->FormEnctype);
        if (!$CCSUseAmp) {
            $Tpl->SetVar("HTMLFormProperties", "method=\"POST\" action=\"" . $this->HTMLFormAction . "\" name=\"" . $this->ComponentName . "\"");
        } else {
            $Tpl->SetVar("HTMLFormProperties", "method=\"post\" action=\"" . str_replace("&", "&amp;", $this->HTMLFormAction) . "\" id=\"" . $this->ComponentName . "\"");
        }
        $Tpl->SetVar("FormState", CCToHTML($this->GetFormState($NonEmptyRows)));
        $Tpl->parse();
        $Tpl->block_path = $ParentPath;
        $this->DataSource->close();
    }
//End Show Method

} //End inreceipts Class @2-FCB6E20C

class clsinreceiptsDataSource extends clsDBCoopWorksConn {  //inreceiptsDataSource Class @2-C77800FB

//DataSource Variables @2-8204DAB6
    var $Parent = "";
    var $CCSEvents = "";
    var $CCSEventResult;
    var $ErrorBlock;
    var $CmdExecution;

    var $UpdateParameters;
    var $CountSQL;
    var $wp;
    var $AllParametersSet;

    var $CachedColumns;
    var $CurrentRow;

    // Datasource fields
    var $RceptNbr;
    var $recid;
    var $TranDate;
    var $InvtId;
    var $Site;
    var $Qty;
    var $UnitCost;
    var $StkQtyFactor;
    var $TranCost;
    var $Confirmed;
//End DataSource Variables

//DataSourceClass_Initialize Event @2-761CB755
    function clsinreceiptsDataSource(& $Parent)
    {
        $this->Parent = & $Parent;
        $this->ErrorBlock = "EditableGrid inreceipts/Error";
        $this->Initialize();
        $this->RceptNbr = new clsField("RceptNbr", ccsText, "");
        
        $this->recid = new clsField("recid", ccsInteger, "");
        
        $this->TranDate = new clsField("TranDate", ccsDate, $this->DateFormat);
        
        $this->InvtId = new clsField("InvtId", ccsText, "");
        
        $this->Site = new clsField("Site", ccsText, "");
        
        $this->Qty = new clsField("Qty", ccsFloat, "");
        
        $this->UnitCost = new clsField("UnitCost", ccsFloat, "");
        
        $this->StkQtyFactor = new clsField("StkQtyFactor", ccsFloat, "");
        
        $this->TranCost = new clsField("TranCost", ccsFloat, "");
        
        $this->Confirmed = new clsField("Confirmed", ccsInteger, "");
        

    }
//End DataSourceClass_Initialize Event

//SetOrder Method @2-5A68D5EE
    function SetOrder($SorterName, $SorterDirection)
    {
        $this->Order = "";
        $this->Order = CCGetOrder($this->Order, $SorterName, $SorterDirection, 
            array("Sorter1" => array("TranDate", ""), 
            "Sorter2" => array("InvtId", ""), 
            "Sorter3" => array("Site", ""), 
            "Sorter4" => array("Qty", ""), 
            "Sorter5" => array("UnitCost", ""), 
            "Sorter6" => array("StkQtyFactor", ""), 
            "Sorter7" => array("Confirmed", "")));
    }
//End SetOrder Method

//Prepare Method @2-4B6035DE
    function Prepare()
    {
        global $CCSLocales;
        global $DefaultDateFormat;
        $this->wp = new clsSQLParameters($this->ErrorBlock);
        $this->wp->AddParameter("1", "urlConfirmed", ccsInteger, "", "", $this->Parameters["urlConfirmed"], 0, false);
        $this->wp->AddParameter("2", "urls_TranDate", ccsDate, array("mm", "/", "dd", "/", "yyyy"), $this->DateFormat, $this->Parameters["urls_TranDate"], "", false);
        $this->wp->AddParameter("3", "urls_Site", ccsText, "", "", $this->Parameters["urls_Site"], "", false);
        $this->AllParametersSet = $this->wp->AllParamsSet();
        $this->wp->Criterion[1] = $this->wp->Operation(opEqual, "Confirmed", $this->wp->GetDBValue("1"), $this->ToSQL($this->wp->GetDBValue("1"), ccsInteger),false);
        $this->wp->Criterion[2] = $this->wp->Operation(opLessThanOrEqual, "TranDate", $this->wp->GetDBValue("2"), $this->ToSQL($this->wp->GetDBValue("2"), ccsDate),false);
        $this->wp->Criterion[3] = $this->wp->Operation(opContains, "Site", $this->wp->GetDBValue("3"), $this->ToSQL($this->wp->GetDBValue("3"), ccsText),false);
        $this->Where = $this->wp->opAND(
             false, $this->wp->opAND(
             false, 
             $this->wp->Criterion[1], 
             $this->wp->Criterion[2]), 
             $this->wp->Criterion[3]);
    }
//End Prepare Method

//Open Method @2-D8C1493F
    function Open()
    {
        $this->CCSEventResult = CCGetEvent($this->CCSEvents, "BeforeBuildSelect", $this->Parent);
        $this->CountSQL = "SELECT COUNT(*)\n\n" .
        "FROM inreceipts";
        $this->SQL = "SELECT * \n\n" .
        "FROM inreceipts {SQL_Where} {SQL_OrderBy}";
        $this->CCSEventResult = CCGetEvent($this->CCSEvents, "BeforeExecuteSelect", $this->Parent);
        if ($this->CountSQL) 
            $this->RecordsCount = CCGetDBValue(CCBuildSQL($this->CountSQL, $this->Where, ""), $this);
        else
            $this->RecordsCount = "CCS not counted";
        $this->query($this->OptimizeSQL(CCBuildSQL($this->SQL, $this->Where, $this->Order)));
        $this->CCSEventResult = CCGetEvent($this->CCSEvents, "AfterExecuteSelect", $this->Parent);
    }
//End Open Method

//SetValues Method @2-33848DD0
    function SetValues()
    {
        $this->CachedColumns["recid"] = $this->f("recid");
        $this->RceptNbr->SetDBValue($this->f("RceptNbr"));
        $this->recid->SetDBValue(trim($this->f("recid")));
        $this->TranDate->SetDBValue(trim($this->f("TranDate")));
        $this->InvtId->SetDBValue($this->f("InvtId"));
        $this->Site->SetDBValue($this->f("Site"));
        $this->Qty->SetDBValue(trim($this->f("Qty")));
        $this->UnitCost->SetDBValue(trim($this->f("UnitCost")));
        $this->StkQtyFactor->SetDBValue(trim($this->f("StkQtyFactor")));
        $this->TranCost->SetDBValue(trim($this->f("TranCost")));
        $this->Confirmed->SetDBValue(trim($this->f("Confirmed")));
    }
//End SetValues Method

//Update Method @2-C2AD036A
    function Update()
    {
        global $CCSLocales;
        global $DefaultDateFormat;
        $this->CmdExecution = true;
        $this->cp["xrecid"] = new clsSQLParameter("ctrlrecid", ccsInteger, "", "", $this->recid->GetValue(true), "", false, $this->ErrorBlock);
        $this->cp["xselected"] = new clsSQLParameter("ctrlConfirmed", ccsInteger, "", "", $this->Confirmed->GetValue(true), "", false, $this->ErrorBlock);
        $this->CCSEventResult = CCGetEvent($this->CCSEvents, "BeforeBuildUpdate", $this->Parent);
        if (!is_null($this->cp["xrecid"]->GetValue()) and !strlen($this->cp["xrecid"]->GetText()) and !is_bool($this->cp["xrecid"]->GetValue())) 
            $this->cp["xrecid"]->SetValue($this->recid->GetValue(true));
        if (!is_null($this->cp["xselected"]->GetValue()) and !strlen($this->cp["xselected"]->GetText()) and !is_bool($this->cp["xselected"]->GetValue())) 
            $this->cp["xselected"]->SetValue($this->Confirmed->GetValue(true));
        $this->SQL = "CALL IN_Receipts_Confirm (" . $this->ToSQL($this->cp["xrecid"]->GetDBValue(), $this->cp["xrecid"]->DataType) . ", "
             . $this->ToSQL($this->cp["xselected"]->GetDBValue(), $this->cp["xselected"]->DataType) . ");";
        $this->CCSEventResult = CCGetEvent($this->CCSEvents, "BeforeExecuteUpdate", $this->Parent);
        if($this->Errors->Count() == 0 && $this->CmdExecution) {
            $this->query($this->SQL);
            $this->CCSEventResult = CCGetEvent($this->CCSEvents, "AfterExecuteUpdate", $this->Parent);
        }
    }
//End Update Method

} //End inreceiptsDataSource Class @2-FCB6E20C

//Initialize Page @1-ABB89739
// Variables
$FileName = "";
$Redirect = "";
$Tpl = "";
$TemplateFileName = "";
$BlockToParse = "";
$ComponentName = "";
$Attributes = "";

// Events;
$CCSEvents = "";
$CCSEventResult = "";

$FileName = FileName;
$Redirect = "";
$TemplateFileName = "IN_Receipts_Confirm.html";
$BlockToParse = "main";
$TemplateEncoding = "UTF-8";
$ContentType = "text/html";
$PathToRoot = "./";
$Charset = $Charset ? $Charset : "utf-8";
//End Initialize Page

//Authenticate User @1-872FD3D7
CCSecurityRedirect("", "");
//End Authenticate User

//Before Initialize @1-E870CEBC
$CCSEventResult = CCGetEvent($CCSEvents, "BeforeInitialize", $MainPage);
//End Before Initialize

//Initialize Objects @1-B0E06CD6
$DBCoopWorksConn = new clsDBCoopWorksConn();
$MainPage->Connections["CoopWorksConn"] = & $DBCoopWorksConn;
$Attributes = new clsAttributes("page:");
$MainPage->Attributes = & $Attributes;

// Controls
$inreceiptsSearch = & new clsRecordinreceiptsSearch("", $MainPage);
$inreceipts = & new clsEditableGridinreceipts("", $MainPage);
$MainPage->inreceiptsSearch = & $inreceiptsSearch;
$MainPage->inreceipts = & $inreceipts;
$inreceipts->Initialize();

$CCSEventResult = CCGetEvent($CCSEvents, "AfterInitialize", $MainPage);

if ($Charset) {
    header("Content-Type: " . $ContentType . "; charset=" . $Charset);
} else {
    header("Content-Type: " . $ContentType);
}
//End Initialize Objects

//Initialize HTML Template @1-A06E9207
$CCSEventResult = CCGetEvent($CCSEvents, "OnInitializeView", $MainPage);
$Tpl = new clsTemplate($FileEncoding, $TemplateEncoding);
$Tpl->LoadTemplate(PathToCurrentPage . $TemplateFileName, $BlockToParse, "UTF-8", "replace");
$Tpl->block_path = "/$BlockToParse";
$CCSEventResult = CCGetEvent($CCSEvents, "BeforeShow", $MainPage);
$Attributes->SetValue("pathToRoot", "");
$Attributes->Show();
//End Initialize HTML Template

//Execute Components @1-BC6902DC
$inreceiptsSearch->Operation();
$inreceipts->Operation();
//End Execute Components

//Go to destination page @1-88CB8341
if($Redirect)
{
    $CCSEventResult = CCGetEvent($CCSEvents, "BeforeUnload", $MainPage);
    $DBCoopWorksConn->close();
    header("Location: " . $Redirect);
    unset($inreceiptsSearch);
    unset($inreceipts);
    unset($Tpl);
    exit;
}
//End Go to destination page

//Show Page @1-18DBB569
$inreceiptsSearch->Show();
$inreceipts->Show();
$Tpl->block_path = "";
$Tpl->Parse($BlockToParse, false);
if (!isset($main_block)) $main_block = $Tpl->GetVar($BlockToParse);
$CCSEventResult = CCGetEvent($CCSEvents, "BeforeOutput", $MainPage);
if ($CCSEventResult) echo $main_block;
//End Show Page

//Unload Page @1-0D31A11E
$CCSEventResult = CCGetEvent($CCSEvents, "BeforeUnload", $MainPage);
$DBCoopWorksConn->close();
unset($inreceiptsSearch);
unset($inreceipts);
unset($Tpl);
//End Unload Page


?>
Return current item: CoopWorks Farmers Association Management