Exemplo n.º 1
0
    /**
     * Prepare documents of subsection to view
     * @param $documents
     * @param $vendorId
     * @param $sectionFolderCategory
     * @param $year
     * @return array
     */
    public static function prepareDocumentsOfSubsectionToView($documents, $vendorId, $sectionFolderCategory, $year)
    {
        $result = array();

        // if section is W9 Book, add all available for company W9s (they are not in LibraryDocs)
        if ($sectionFolderCategory == Sections::W9_BOOK) {
            $w9Docs = W9::getAvailableW9sOfYear($year);
            foreach ($w9Docs as $w9Doc) {
                $result[] = $w9Doc;
            }
        }

        foreach($documents as $document) {
            $result[] = $document->document;
        }

        // if section is Vendor Documents, add last available for company W9s of this vendor (it is not in LibraryDocs)
        if ($vendorId != 0 && $sectionFolderCategory == Sections::VENDOR_DOCUMENTS) {
            $vendor = Vendors::model()->with('client')->findByPk($vendorId);
            if ($vendor) {
                $document = W9::getCompanyW9Doc($vendor->client->Client_ID);
                if ($document) {
                    $result[] = $document;
                }
            }
        }

        return $result;
    }
Exemplo n.º 2
0
    /**
     * Delete document with rows in relative tables
     * @param $documentId
     */
    public static function deleteDocument($documentId) {
        $document = Documents::model()->findByPk($documentId);
        if ($document) {
            if ($document->Document_Type == self::W9) {
                $w9s = W9::model()->findAllByAttributes(array(
                    'Document_ID' => $documentId,
                ));
                foreach ($w9s as $w9) {
                    W9::deleteW9($w9->W9_ID);
                }
            } else if ($document->Document_Type == self::AP) {
                $ap = Aps::model()->findByAttributes(array(
                    'Document_ID' => $documentId,
                ));
                if ($ap) {
                    Aps::deleteAP($ap->AP_ID);
                }
            } else if ($document->Document_Type ==  self::PM) {
                $payment = Payments::model()->findByAttributes(array(
                    'Document_ID' => $documentId,
                ));
                if ($payment) {
                    Payments::deletePayment($payment->Payment_ID);
                }
            } else if ($document->Document_Type == self::PO) {
                $po = Pos::model()->findByAttributes(array(
                    'Document_ID' => $documentId,
                ));
                if ($po) {
                    Pos::deletePO($po->PO_ID);
                }
            } else if ($document->Document_Type == self::PC) {
                $pc = Pcs::model()->findByAttributes(array(
                    'Document_ID' => $documentId,
                ));
                if ($pc) {
                    Pcs::deletePC($pc->PC_ID);
                }
            } else if ($document->Document_Type == self::AR) {
                $ar = Ars::model()->findByAttributes(array(
                    'Document_ID' => $documentId,
                ));
                if ($ar) {
                    Ars::deleteAR($ar->AR_ID);
                }
            } else if ($document->Document_Type == self::PR) {
                $payroll = Payrolls::model()->findByAttributes(array(
                    'Document_ID' => $documentId,
                ));
                if ($payroll) {
                    Payrolls::deletePayroll($payroll->Payroll_ID);
                }
            }  else {
                $image = $document->image;
                $image->delete();
                $document->delete();

                // delete thumbnail
                $filePath = 'protected/data/thumbs/' . $documentId . '.jpg';
                if (file_exists($filePath)) {
                    @unlink($filePath);
                }

                // delete library links
                LibraryDocs::deleteDocumentLinks($documentId);
            }
        }
    }
Exemplo n.º 3
0
    /**
     * Copy Vendors list from one client to another
     * @param $toClientId
     * @param $fromClientId
     */
    public static function copyVendorsList($toClientId, $fromClientId)
    {
        //get existing vendors for client

        $sql='select v1.Vendor_ID_Shortcut,v1.Vendor_Client_ID,v1.Vendor_Name_Checkprint, v1.Vendor_1099,v1.Vendor_Default_GL,v1.Vendor_Default_GL_Note from vendors v1
        left join clients c on (c.Client_ID = v1.Client_Client_ID)
        where v1.Client_Client_ID = '.$fromClientId.
            ' and v1.Vendor_Client_ID not in (
			select v2.Vendor_Client_ID from vendors v2
					left join clients c on (c.Client_ID = v2.Client_Client_ID)
			where v2.Client_Client_ID = '.$toClientId. ' and v2.Active_Relationship=1)';

        $list= Yii::app()->db->createCommand($sql)->queryAll();

        $all_amount=count($list);
        $i=0;
        $pb= ProgressBar::init();

        foreach ($list as $vendor) {
            $newVendor = Vendors::model()->findByAttributes(array(
                'Client_Client_ID' => $toClientId,
                'Vendor_Client_ID' => $vendor['Vendor_Client_ID'],
            ));
            if ($newVendor === null) {
                $newVendor = new Vendors();
                $newVendor->Vendor_ID_Shortcut =$vendor['Vendor_ID_Shortcut'];
                $newVendor->Vendor_Client_ID = $vendor['Vendor_Client_ID'];
                $newVendor->Client_Client_ID = $toClientId;
                $newVendor->Vendor_Name_Checkprint = $vendor['Vendor_Name_Checkprint'];
                $newVendor->Vendor_1099 =$vendor['Vendor_1099'];
                $newVendor->Vendor_Default_GL = $vendor['Vendor_Default_GL'];
                $newVendor->Vendor_Default_GL_Note =$vendor['Vendor_Default_GL_Note'] ;
                $newVendor->Active_Relationship = self::ACTIVE_RELATIONSHIP;
                $newVendor->save();

                $w9 = W9::getCompanyW9($vendor['Vendor_Client_ID'], $fromClientId);
                if ($w9 !== null) {
                    $extW9 = W9::model()->findByAttributes(array(
                        'Document_ID' => $w9->Document_ID,
                        'W9_Owner_ID' => $toClientId,
                    ));
                    if ($extW9 === null) {
                        $w9->share($toClientId, $w9->Access_Type);
                    }
                }
            } else {
                $newVendor->Active_Relationship = self::ACTIVE_RELATIONSHIP;
                $newVendor->save();
            }
            $i++;
            $percent=intval($i/$all_amount*100);
            session_start();
            $_SESSION['progress']=$percent;
            session_write_close();
        }

    }
Exemplo n.º 4
0
    public static function createNewFromSessionData($current_upload_file,$client){

        if (file_exists($current_upload_file['filepath'])) {
            // create document

            $document = new Documents();
            $document->Document_Type = $current_upload_file['doctype'];
            $document->User_ID = Yii::app()->user->userID;
            $document->Client_ID = Yii::app()->user->clientID;
            $document->Project_ID = Yii::app()->user->projectID;
            $document->Created = date("Y-m-d H:i:s");
            $document->save();
            $new_doc_id=$document->Document_ID;

            Audits::LogAction($document->Document_ID ,Audits::ACTION_UPLOAD);

            // insert image
            $image = new Images();
            $imageData = addslashes(fread(fopen($current_upload_file['filepath'],"rb"),filesize($current_upload_file['filepath'])));
            //$imageData = FileModification::ImageToPdfByFilePath($current_upload_file['filepath']);
            $image->Document_ID = $document->Document_ID;
            $image->Img = $imageData;
            $image->File_Name = $current_upload_file['name'];
            $image->Mime_Type = $current_upload_file['mimetype'];
            $image->File_Hash = sha1_file($current_upload_file['filepath']);
            $image->File_Size = intval(filesize($current_upload_file['filepath']));
            $image->Pages_Count = FileModification::calculatePagesByPath($current_upload_file['filepath']);

            $image->save();

            $infile = @file_get_contents($current_upload_file['filepath'], FILE_BINARY);
            if (($current_upload_file['mimetype'] == 'application/pdf' && $image->findPdfText($infile) == '')
                || $current_upload_file['mimetype'] != 'application/pdf') {
                Documents::crateDocumentThumbnail($current_upload_file['filepath'], 'thumbs', $current_upload_file['mimetype'], $document->Document_ID, 80);
            }

            // delete file from temporary catalog
            unlink($current_upload_file['filepath']);
        }

        $fedId = trim($current_upload_file['fed_id']);
        $newCompanyName = trim($current_upload_file['company_name']);

        // get company info
        $company = Companies::model()->with('client')->findByAttributes(array(
            'Company_Fed_ID' => $fedId,
        ));

        // create w9
        $W9 = new W9();
        $W9->Document_ID = $document->Document_ID;
        $W9->W9_Owner_ID = Yii::app()->user->clientID;
        $W9->Creator_ID = Yii::app()->user->userID;
        $W9->Business_Name = trim($current_upload_file['bus_name']);
        $W9->Tax_Class =  trim($current_upload_file['tax_name']);

        // get user info
        $user = Users::model()->with('person')->findByPk(Yii::app()->user->userID);

        if ($company) {
            // if company exisits
            $client = $company->client;

            //fill created company with dataentry values from session
            Companies::fillWithSessionDataEntry($company,$current_upload_file);

            $existingW9 = W9::model()->findByAttributes(array(
                'Client_ID' => $client->Client_ID,
                'W9_Owner_ID' => Yii::app()->user->clientID,
            ));

            if ($existingW9) {
                $W9->Revision_ID = -1;
            } else {
                $W9->Revision_ID = 0;
            }

            $vendor = Vendors::model()->findByAttributes(array(
                'Client_Client_ID' => Yii::app()->user->clientID,
                'Vendor_Client_ID' => $client->Client_ID,
            ));

            if (isset($vendor->Active_Relationship) && $vendor->Active_Relationship == Vendors::NOT_ACTIVE_RELATIONSHIP) {
                $vendor->Active_Relationship = Vendors::ACTIVE_RELATIONSHIP;
                $vendor->save();
            } else if (!$vendor && Yii::app()->user->clientID != 0 && Yii::app()->user->clientID != $client->Client_ID) {
                $vendor = new Vendors();
                $vendor->Vendor_ID_Shortcut = '';
                $vendor->Vendor_Client_ID = $client->Client_ID;
                $vendor->Client_Client_ID = Yii::app()->user->clientID;
                $vendor->Vendor_Name_Checkprint = '';
                $vendor->Vendor_1099 = '';
                $vendor->Vendor_Default_GL = '';
                $vendor->Vendor_Default_GL_Note = '';
                $vendor->Vendor_Note_General = '';
                $vendor->save();
            }
        } else {
            //if company does not exists, create new company

            $company_model = Companies::model()->findByPk($client->Company_ID);
            //fill created company with dataentry values from session
            Companies::fillWithSessionDataEntry($company_model,$current_upload_file);

            if (Yii::app()->user->clientID != 0) {
                $vendor = new Vendors();
                $vendor->Vendor_ID_Shortcut = '';
                $vendor->Vendor_Client_ID = $company_model->Company_ID;
                $vendor->Client_Client_ID = Yii::app()->user->clientID;
                $vendor->Vendor_Name_Checkprint = '';
                $vendor->Vendor_1099 = '';
                $vendor->Vendor_Default_GL = '';
                $vendor->Vendor_Default_GL_Note = '';
                $vendor->Vendor_Note_General = '';
                $vendor->save();
            }

            $W9->Revision_ID = 0;
        }

        // save w9
        $W9->Client_ID = $client->Client_ID;
        $W9->save();

        return $W9;

    }
Exemplo n.º 5
0
    public function appendGeneralDocList ($client_id,$project_list,$doc_type){

        $condition = new CDbCriteria();
        $condition->condition =' documents.Client_ID = '.$client_id;
        $condition->addInCondition('documents.Project_ID ',$project_list);
        $condition->join = 'left join documents on documents.Document_ID = t.Document_ID';

        if ($doc_type=='PC') {
            $models = Pcs::model()->with('document')->findAll($condition);
        } else if ($doc_type=='W9') {
            $models = W9::model()->with('document')->findAll($condition);
        } else if ($doc_type=='JE') {
            $models = Journals::model()->with('document')->findAll($condition);
        } else if ($doc_type=='AR') {
            $models = Ars::model()->with('document')->findAll($condition);
        } else if ($doc_type=='PR') {
            $models = Payrolls::model()->with('document')->findAll($condition);
        } else if ($doc_type=='GF') {
            //$models = G::model()->findAll($condition);
        } else if ($doc_type=='PM') {
            $models = Payments::model()->with('document')->findAll($condition);
        } else if ($doc_type=='PC') {
            $models = Ars::model()->with('document')->findAll($condition);
        }




        $xml_doc = $this->xml->createElement("document");
        if($models) {
            foreach ($models as $model) {
                $xml_row = $this->xml->createElement("row");

                foreach ($model->attributes as $key => $value) {
                    $xml_field = $this->xml->createElement("field",htmlentities($value,ENT_QUOTES | 'ENT_XML1'));
                    $xml_field->setAttribute('name', $key);
                    $xml_row->appendChild($xml_field);
                }
                    //+ we need to insert several columns from document model
                        $xml_field = $this->xml->createElement("field",htmlentities($model->document->Origin,ENT_QUOTES | 'ENT_XML1'));
                        $xml_field->setAttribute('name', 'DocumentsOrigin');
                        $xml_row->appendChild($xml_field);
                            $xml_field = $this->xml->createElement("field",htmlentities($model->document->Created,ENT_QUOTES | 'ENT_XML1'));
                            $xml_field->setAttribute('name', 'DocumentsCreated');
                            $xml_row->appendChild($xml_field);
                                $xml_field = $this->xml->createElement("field",htmlentities($model->document->Project_ID,ENT_QUOTES | 'ENT_XML1'));
                                $xml_field->setAttribute('name', 'DocumentsProject_ID');
                                $xml_row->appendChild($xml_field);
                    // end of block

                $xml_doc_row = $this->xml->createElement("documents");
                foreach ($model->document->attributes as $key => $value) {
                    $xml_field = $this->xml->createElement("field",htmlentities($value,ENT_QUOTES | 'ENT_XML1'));
                    $xml_field->setAttribute('name', $key);
                    $xml_doc_row->appendChild($xml_field);
                }

                /**/
                $xml_image_row = $this->xml->createElement("images");
                    $xml_field = $this->xml->createElement("field",$model->document->image->Image_ID);
                    $xml_field->setAttribute('name', 'Image_ID');
                    $xml_image_row->appendChild($xml_field);

                            $filename = FileModification::prepareFileForExport($model->document->image->Document_ID,$doc_type,$this->filepath);
                            $xml_field = $this->xml->createElement("field",$filename);
                            $xml_field->setAttribute('name', 'File_Name');
                            $xml_image_row->appendChild($xml_field);
                            $xml_row->appendChild($xml_field);

                                $xml_field = $this->xml->createElement("field",$model->document->image->Mime_Type);
                                $xml_field->setAttribute('name', 'Mime_Type');
                                $xml_image_row->appendChild($xml_field);
                                $xml_row->appendChild($xml_field);

                                    $xml_field = $this->xml->createElement("field",$model->document->image->Pages_Count);
                                    $xml_field->setAttribute('name', 'Pages_Count');
                                    $xml_image_row->appendChild($xml_field);
                                    $xml_row->appendChild($xml_field);
                                /**/

                $xml_row->appendChild($xml_doc_row);
                $xml_row->appendChild($xml_image_row);
                $xml_doc->appendChild($xml_row);


            }
            $this->wrapper->appendChild($xml_doc);

        }
    }
Exemplo n.º 6
0
    /**
     * Create project shelve and cabinet
     * @param $projectId
     * @param $year
     */
    public static function createProjectStorages($projectId, $year)
    {
        $project = Projects::model()->findByPk($projectId);

        // check existing project cabinet
        $cabinet = Storages::model()->findByAttributes(array(
            'Storage_Type' => self::CABINET,
            'Created_By' => '0',
            'Project_ID' => $projectId,
            'Year' => $year,
        ));
        if (!$cabinet) {
            // if there is not cabinet for this project create it
            $cabinet = new Storages();
            $cabinet->Storage_Name = $project->Project_Name;
            $cabinet->Project_ID = $projectId;
            $cabinet->Client_ID = Yii::app()->user->clientID;
            $cabinet->Year = $year;
            $cabinet->Created_By = 0;
            $cabinet->Row_Num = 0;
            $cabinet->Storage_Type = self::CABINET;
            $cabinet->Access_Type = self::HAS_ACCESS;
            if ($cabinet->validate()) {
                $cabinet->save();
            }
        }

        // check existing project shelf
        $shelf = Storages::model()->findByAttributes(array(
            'Storage_Type' => self::SHELF,
            'Created_By' => '0',
            'Project_ID' => $projectId,
            'Year' => $year,
        ));
        if (!$shelf) {
            // if there is not cabinet for this project create it
            $shelf = new Storages();
            $shelf->Storage_Name = $project->Project_Name;
            $shelf->Project_ID = $projectId;
            $shelf->Client_ID = Yii::app()->user->clientID;
            $shelf->Year = $year;
            $shelf->Created_By = 0;
            $shelf->Row_Num = 0;
            $shelf->Storage_Type = self::SHELF;
            $shelf->Access_Type = self::HAS_ACCESS;
            if ($shelf->validate()) {
                $shelf->save();
            }
        }

        $countW9s = W9::getCountOfAvailableW9sOfYear($year);
        if ($countW9s > 0) {
            // also crete W9 book if it does not exist and there are Company's W9s
            $w9Binder = Sections::model()->findByAttributes(array(
                'Section_Type' => self::SHELF,
                'Created_By' => '0',
                'Storage_ID' => $shelf->Storage_ID,
                'Folder_Cat_ID' => Sections::W9_BOOK,
            ));

            if (!$w9Binder) {
                $w9Binder = new Sections();
                $w9Binder->Storage_ID = $shelf->Storage_ID;
                $w9Binder->Section_Name = "W9s";
                $w9Binder->Vendor_ID = 0;
                $w9Binder->Created_By = 0;
                $w9Binder->Section_Type = self::SHELF;
                $w9Binder->Folder_Cat_ID = Sections::W9_BOOK;
                $w9Binder->Access_Type = self::HAS_ACCESS;
                if ($w9Binder->validate()) {
                    $w9Binder->save();

                    $tab = new Subsections();
                    $tab->Section_ID = $w9Binder->Section_ID;
                    $tab->Subsection_Name = 'Tab 1';
                    $tab->Subsection_Type = self::SHELF;
                    $tab->Created_By = 0;
                    $tab->Access_Type = self::HAS_ACCESS;
                    $tab->save();
                }
            }
        }
    }
Exemplo n.º 7
0
	/**
	 * Lists all models.
	 */
	public function actionIndex()
	{
        if (isset($_POST['oper']) && $_POST['oper'] == 'edit') {
            $w9Id = intval($_POST["id"]);
            $w9 = W9::model()->with('client')->findByPk($w9Id);

            if ($w9) {
                $client = $w9->client;
                $company = $client->company;
                $addresses = $company->adreses;

                if (isset($addresses[0])) {
                    $address = $addresses[0];
                    $address->Address1 =  $_POST["Address1"];
                    $address->Address2 =  $_POST["Address2"];
                    $address->City =  $_POST["City"];
                    $address->State =  $_POST["State"];
                    $address->ZIP =  $_POST["ZIP"];
                    $address->Country =  $_POST["Country"];
                    $address->Phone =  $_POST["Phone"];
                    $address->Fax =  $_POST["Fax"];
                    if ($address->validate()) {
                        $address->save();
                        echo "adresses\n";
                    }
                }

                if ($company) {
                    $company->Company_Name = $_POST["Company_Name"];
                    $company->Company_Fed_ID = $_POST["Company_Fed_ID"];
                    $company->Email = $_POST["Email"];
                    $company->SSN = $_POST["SSN"];
                    $company->Business_NameW9 = $_POST["Business_NameW9"];
                    if ($company->validate()) {
                        $company->save();
                        echo "company\n";
                    }
                }

                $w9->Verified = $_POST["Verified"];
                $w9->Business_Name = $_POST["Business_Name"];
                $w9->Exempt = $_POST["Exempt"];
                $w9->Tax_Class = $_POST["Tax_Class"];
                $w9->Account_Nums = $_POST["Account_Nums"];
                $w9->Signed = $_POST["Account_Nums"];
                $w9->Signature_Date = $_POST["Signature_Date"] ? $_POST["Signature_Date"] : null;
                $w9->Revision_ID = $_POST["Revision_ID"];
                if ($w9->validate()) {
                    $w9->save();
                    echo "w9\n";
                }
            }

            die;
        }

        if (isset($_POST['oper']) && $_POST['oper'] == 'add') {
            die;
        }

        if (isset($_POST['oper']) && $_POST['oper'] == 'del') {
            $w9Id = intval($_POST["id"]);
            $w9 = W9::model()->findByPk($w9Id);
            if ($w9) {
                W9::deleteW9($w9Id);
            }
            die;
        }

        $conn = mysql_connect(Yii::app()->params->dbhost, Yii::app()->params->dbuser, Yii::app()->params->dbpassword);
        mysql_select_db(Yii::app()->params->dbname);
        mysql_query("SET NAMES 'utf8'");

        Yii::import('ext.phpgrid.inc.jqgrid');

        // set columns
        $col = array();
        $col["title"] = "W9 ID"; // caption of column
        $col["name"] = "W9_ID";
        $col["dbname"] = "w9.W9_ID"; // grid column name, same as db field or alias from sql
        $col["resizable"] = false;
        $col["editable"] = false; // this column is editable
        $col["hidden"] = false;
        $col["viewable"] = true;
        $col["search"] = false;
        $col["sortable"] = false;
        $cols[] = $col;

        // set columns
        $col = array();
        $col["title"] = "Document ID"; // caption of column
        $col["name"] = "Document_ID";
        $col["dbname"] = "w9.Document_ID"; // grid column name, same as db field or alias from sql
        $col["resizable"] = false;
        $col["editable"] = false; // this column is editable
        $col["hidden"] = true;
        $col["viewable"] = true;
        $col["search"] = false;
        $col["sortable"] = false;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Business Name"; // caption of column
        $col["name"] = "Business_Name";
        $col["dbname"] = "w9.Business_Name"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $cols[] = $col;

        $col = array();
        $col["title"] = "W9 Data Entry"; // caption of column
        $col["name"] = "W9_Data_Entry";
        $col["dbname"] = "w9.W9_Data_Entry"; // grid column name, same as db field or alias from sql
        $col["resizable"] = false;
        $col["editable"] = false; // this column is editable
        $col["hidden"] = true;
        $col["viewable"] = true;
        $col["search"] = false;
        $col["sortable"] = false;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Tax Class"; // caption of column
        $col["name"] = "Tax_Class";
        $col["dbname"] = "w9.Tax_Class"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $col["edittype"] = "select";
        $col["editoptions"] = array("value"=>'0:0;SP:SP;C:C;CC:CC;CS:CS;PS:PS;TE:TE;LL:LL;LC:LC;LS:LS;LP:LP;OT:OT');
        $cols[] = $col;

        $col = array();
        $col["title"] = "Exempt"; // caption of column
        $col["name"] = "Exempt";
        $col["dbname"] = "w9.Exempt"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["edittype"] = "select";
        $col["search"] = false;
        $col["editoptions"] = array("value"=>'0:0;1:1');
        $cols[] = $col;

        $col = array();
        $col["title"] = "Account Nums"; // caption of column
        $col["name"] = "Account_Nums";
        $col["dbname"] = "w9.Account_Nums"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["search"] = false;
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Signed"; // caption of column
        $col["name"] = "Signed";
        $col["dbname"] = "w9.Signed"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["edittype"] = "select";
        $col["search"] = false;
        $col["editoptions"] = array("value"=>'0:0;1:1');
        $cols[] = $col;

        $col = array();
        $col["title"] = "Signature Date"; // caption of column
        $col["name"] = "Signature_Date";
        $col["dbname"] = "w9.Signature_Date"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["search"] = false;
        $col["viewable"] = true;
        $col["formatter"] = "date";
        $col["formatoptions"] = array("srcformat"=>'Y-m-d',"newformat"=>'Y-m-d');
        $cols[] = $col;

        $col = array();
        $col["title"] = "Verified"; // caption of column
        $col["name"] = "Verified";
        $col["dbname"] = "w9.Verified"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["edittype"] = "select";
        $col["editoptions"] = array("value"=>'0:0;1:1');
        $cols[] = $col;

        $revisions = W9Revisions::model()->findAll();
        $revIds[] = '-1:-1';
        $revIds[] = '0:0';
        foreach ($revisions as $revision) {
            $revIds[] = $revision->Revision_ID . ':' . $revision->Revision_ID;
        }

        $col = array();
        $col["title"] = "Revision ID"; // caption of column
        $col["name"] = "Revision_ID";
        $col["dbname"] = "w9.Revision_ID"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["edittype"] = "select";
        $col["editoptions"] = array("value"=>implode(';', $revIds));
        $cols[] = $col;

        $col = array();
        $col["title"] = "File Name"; // caption of column
        $col["name"] = "File_Name";
        $col["dbname"] = "images.File_Name"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = false; // this column is editable
        $col["viewable"] = true;
        $col["search"] = true;
        $col["default"] = "<span class='image_view' data='{Document_ID}'>{File_Name}</span>";
        $cols[] = $col;

        $col = array();
        $col["title"] = "Mime Type"; // caption of column
        $col["name"] = "Mime_Type";
        $col["dbname"] = "images.Mime_Type"; // grid column name, same as db field or alias from sql
        $col["resizable"] = false;
        $col["editable"] = false; // this column is editable
        $col["viewable"] = true;
        $col["search"] = true;
        $col["sortable"] = true;
        $cols[] = $col;

        // set columns
        $col = array();
        $col["title"] = "Company ID"; // caption of column
        $col["name"] = "Company_ID";
        $col["dbname"] = "companies.Company_ID"; // grid column name, same as db field or alias from sql
        $col["resizable"] = false;
        $col["editable"] = false; // this column is editable
        $col["hidden"] = false;
        $col["viewable"] = true;
        $col["search"] = false;
        $col["sortable"] = false;
        $cols[] = $col;

        // set columns
        $col = array();
        $col["title"] = "Company Name"; // caption of column
        $col["name"] = "Company_Name";
        $col["dbname"] = "companies.Company_Name"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = true;
        $col["sortable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Fed ID"; // caption of column
        $col["name"] = "Company_Fed_ID";
        $col["dbname"] = "companies.Company_Fed_ID"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        // set columns
        $col = array();
        $col["title"] = "SSN"; // caption of column
        $col["name"] = "SSN";
        $col["dbname"] = "companies.SSN"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = true;
        $col["sortable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Email"; // caption of column
        $col["name"] = "Email";
        $col["dbname"] = "companies.Email"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Business_NameW9"; // caption of column
        $col["name"] = "Business_NameW9";
        $col["dbname"] = "companies.Business_NameW9"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Address1"; // caption of column
        $col["name"] = "Address1";
        $col["dbname"] = "addresses.Address1"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Address2"; // caption of column
        $col["name"] = "Address2";
        $col["dbname"] = "addresses.Address2"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "City"; // caption of column
        $col["name"] = "City";
        $col["dbname"] = "addresses.City"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "State"; // caption of column
        $col["name"] = "State";
        $col["dbname"] = "addresses.State"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "ZIP"; // caption of column
        $col["name"] = "ZIP";
        $col["dbname"] = "addresses.ZIP"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Country"; // caption of column
        $col["name"] = "Country";
        $col["dbname"] = "addresses.Country"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Phone"; // caption of column
        $col["name"] = "Phone";
        $col["dbname"] = "addresses.Phone"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Fax"; // caption of column
        $col["name"] = "Fax";
        $col["dbname"] = "addresses.Fax"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $cols[] = $col;


        $g = new jqgrid();

        $grid["caption"] = "W9";
       // $grid["multiselect"] = true;
        $grid["autowidth"] = true;
        $grid["resizable"] = true;
        //$grid["toppager"] = true;
        $grid["sortname"] = 'companies.Company_Name';
        $grid["sortorder"] = "ASC";
        $grid["add_options"] = array(
            'width'=>'420',
            "closeAfterEdit"=>true, // close dialog after add/edit
            "top"=>"200", // absolute top position of dialog
            "left"=>"200" // absolute left position of dialog
        );

        $g->set_options($grid);

        $g->set_actions(array(
                "add"=>false, // allow/disallow add
                "edit"=>true, // allow/disallow edit
                "delete"=>true, // allow/disallow delete
                "rowactions"=>true, // show/hide row wise edit/del/save option
                "export"=>true, // show/hide export to excel option
                "autofilter" => true, // show/hide autofilter for search
                "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
            )
        );

        $g->select_command = "SELECT   companies.*, addresses.*,
                                       w9.*, images.File_Name, images.Mime_Type
                              FROM w9
                              LEFT JOIN documents ON documents.Document_ID = w9.Document_ID
                              LEFT JOIN images ON images.Document_ID = documents.Document_ID
                              LEFT JOIN clients ON clients.Client_ID = w9.Client_ID
                              LEFT JOIN companies ON clients.Company_ID = companies.Company_ID
                              LEFT JOIN company_addresses ON company_addresses.Company_ID = companies.Company_ID
                              LEFT JOIN addresses ON addresses.Address_ID = company_addresses.Address_ID";

        // set database table for CRUD operations
        $g->table = "w9";

        $g->set_columns($cols);

        // group columns header
        $g->set_group_header( array(
                "useColSpanStyle"=>true,
                "groupHeaders"=>array(
                    array(
                        "startColumnName"=>'W9_ID', // group starts from this column
                        "numberOfColumns"=>11, // group span to next 2 columns
                        "titleText"=>'W9 Information' // caption of group header
                    ),
                    array(
                        "startColumnName"=>'File_Name', // group starts from this column
                        "numberOfColumns"=>2, // group span to next 2 columns
                        "titleText"=>'Image Information' // caption of group header
                    ),
                    array(
                        "startColumnName"=>'Company_ID', // group starts from this column
                        "numberOfColumns"=>6, // group span to next 2 columns
                        "titleText"=>'Company Information' // caption of group header
                    ),
                    array(
                        "startColumnName"=>'Address1', // group starts from this column
                        "numberOfColumns"=>8, // group span to next 2 columns
                        "titleText"=>"Company's Address" // caption of group header
                    )
                )
            )
        );

        // render grid and get html/js output
        $out = $g->render("w9");

        $this->render('index',array(
            'out'=>$out,
        ));
	}
Exemplo n.º 8
0
	/**
	 * Lists all models.
	 */
	public function actionIndex()
	{
        if (isset($_POST['oper']) && $_POST['oper'] == 'del') {
            $w9RevId = trim($_POST["id"]);
            $w9Rev = W9Revisions::model()->findByAttributes(array(
                'Revision_ID' => $w9RevId,
            ));
            $w9s = W9::model()->findByAttributes(array(
                'Revision_ID' => $w9RevId,
            ));
            if ($w9Rev && !$w9s) {
                $w9Rev->delete();
            }
            die;
        }

        $conn = mysql_connect(Yii::app()->params->dbhost, Yii::app()->params->dbuser, Yii::app()->params->dbpassword);
        mysql_select_db(Yii::app()->params->dbname);
        mysql_query("SET NAMES 'utf8'");

        Yii::import('ext.phpgrid.inc.jqgrid');

        // set columns
        $col = array();
        $col["title"] = "Revision ID"; // caption of column
        $col["name"] = "Revision_ID";
        $col["dbname"] = "Revision_ID"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["hidden"] = false;
        $col["viewable"] = true;
        $col["search"] = true;
        $col["sortable"] = true;
        $cols[] = $col;

        // set columns
        $col = array();
        $col["title"] = "Description"; // caption of column
        $col["name"] = "Description";
        $col["dbname"] = "Description"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["hidden"] = false;
        $col["viewable"] = true;
        $col["search"] = true;
        $col["sortable"] = true;
        $cols[] = $col;


        $g = new jqgrid();

        $grid["caption"] = "W9 Revisions";
       // $grid["multiselect"] = true;
        $grid["autowidth"] = true;
        $grid["resizable"] = true;
        //$grid["toppager"] = true;
        $grid["sortname"] = 'Revision_ID';
        $grid["sortorder"] = "ASC";
        $grid["add_options"] = array(
            'width'=>'420',
            "closeAfterEdit"=>true, // close dialog after add/edit
            "top"=>"200", // absolute top position of dialog
            "left"=>"200" // absolute left position of dialog
        );

        $g->set_options($grid);

        $g->set_actions(array(
                "add"=>true, // allow/disallow add
                "edit"=>true, // allow/disallow edit
                "delete"=>true, // allow/disallow delete
                "rowactions"=>true, // show/hide row wise edit/del/save option
                "export"=>true, // show/hide export to excel option
                "autofilter" => true, // show/hide autofilter for search
                "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
            )
        );

        $g->select_command = "SELECT   *
                              FROM w9_revisions";

        // set database table for CRUD operations
        $g->table = "w9_revisions";

        $g->set_columns($cols);

        // group columns header
        $g->set_group_header( array(
                "useColSpanStyle"=>true,
                "groupHeaders"=>array(
                    array(
                        "startColumnName"=>'Revision_ID', // group starts from this column
                        "numberOfColumns"=>2, // group span to next 2 columns
                        "titleText"=>'W9 Revisions' // caption of group header
                    ),
                )
            )
        );

        // render grid and get html/js output
        $out = $g->render("w9revisions");

        $this->render('index',array(
            'out'=>$out,
        ));
	}
Exemplo n.º 9
0
	/**
	 * Lists all models.
	 */
	public function actionIndex()
	{
        if (isset($_POST['oper']) && $_POST['oper'] == 'edit') {
            $companyId = intval($_POST["id"]);
            $company = Companies::model()->with('client', 'adreses')->findByPk($companyId);
            if ($company) {
                if ($company->client) {
                    $client = $company->client;
                    $client->Client_Number = $_POST["Client_Number"];
                    $client->Client_Logo_Name = $_POST["Client_Logo_Name"];
                    $client->Client_Approval_Amount_1 = $_POST["Client_Approval_Amount_1"] ? $_POST["Client_Approval_Amount_1"] : null;
                    $client->Client_Approval_Amount_2 = $_POST["Client_Approval_Amount_2"] ? $_POST["Client_Approval_Amount_2"] : null;
                    if ($client->validate()) {
                        $client->save();
                        echo "client\n";
                    }
                }

                if ($company->adreses) {
                    $addresses = $company->adreses;
                    if (isset($addresses[0])) {
                        $address = $addresses[0];
                        $address->Address1 =  $_POST["Address1"];
                        $address->Address2 =  $_POST["Address2"];
                        $address->City =  $_POST["City"];
                        $address->State =  $_POST["State"];
                        $address->ZIP =  $_POST["ZIP"];
                        $address->Country =  $_POST["Country"];
                        $address->Phone =  $_POST["Phone"];
                        $address->Fax =  $_POST["Fax"];

                        if ($address->validate()) {
                            $address->save();
                            echo "address\n";
                        }
                    }
                }

                $company->Company_Name = $_POST["Company_Name"];
                $company->Company_Fed_ID = $_POST["Company_Fed_ID"];
                $company->Email = $_POST["Email"];
                $company->SSN = $_POST["SSN"];
                $company->Business_NameW9 = $_POST["Business_NameW9"];

                if ($company->validate()) {
                    $company->save();
                    echo "company\n";
                }
            }
            die;
        }

        if (isset($_POST['oper']) && $_POST['oper'] == 'add') {
            die;
        }

        if (isset($_POST['oper']) && $_POST['oper'] == 'del') {
            $companyId = intval($_POST["id"]);
            $company = Companies::model()->with('client', 'adreses')->findByPk($companyId);
            $documents = Documents::model()->findByAttributes(array(
                'Client_ID' => $company->client->Client_ID,
            ));

            if ($company && !$documents) {
                if ($company->client) {
                    $client = $company->client;

                    UsersToApprove::model()->deleteAllByAttributes(array(
                        'Client_ID' => $client->Client_ID,
                    ));

                    UsersClientList::model()->deleteAllByAttributes(array(
                        'Client_ID' => $client->Client_ID,
                    ));

                    UsersProjectList::model()->deleteAllByAttributes(array(
                        'Client_ID' => $client->Client_ID,
                    ));

                    BankAcctNums::model()->deleteAllByAttributes(array(
                        'Client_ID' => $client->Client_ID,
                    ));

                    Coa::model()->deleteAllByAttributes(array(
                        'Client_ID' => $client->Client_ID,
                    ));

                    Vendors::model()->deleteAllByAttributes(array(
                        'Client_Client_ID' => $client->Client_ID,
                    ));

                    Vendors::model()->deleteAllByAttributes(array(
                        'Vendor_Client_ID' => $client->Client_ID,
                    ));

                    $w9s = W9::model()->findAllByAttributes(array(
                        'Client_ID' => $client->Client_ID,
                    ));

                    if ($w9s) {
                        foreach ($w9s as $w9) {
                            W9::deleteW9($w9->W9_ID);
                        }
                    }

                    $projects = Projects::model()->findAllByAttributes(array(
                        'Client_ID' => $client->Client_ID,
                    ));

                    if ($projects) {
                        foreach ($projects as $project) {
                            PoFormatting::model()->deleteAllByAttributes(array(
                                'Project_ID' => $project->Project_ID,
                            ));
                            $project->delete();
                        }
                    }

                    $client->delete();
                }

                if ($company->adreses) {
                    $addresses = $company->adreses;
                    foreach ($addresses as $address) {
                        $address->delete();
                    }
                }

                CompanyAddresses::model()->deleteAllByAttributes(array(
                    'Company_ID' => $companyId,
                ));

                $company->delete();
            }
            die;
        }

        $conn = mysql_connect(Yii::app()->params->dbhost, Yii::app()->params->dbuser, Yii::app()->params->dbpassword);
        mysql_select_db(Yii::app()->params->dbname);
        mysql_query("SET NAMES 'utf8'");

        Yii::import('ext.phpgrid.inc.jqgrid');

        // set columns
        $col = array();
        $col["title"] = "Company ID"; // caption of column
        $col["name"] = "Company_ID";
        $col["dbname"] = "companies.Company_ID"; // grid column name, same as db field or alias from sql
        $col["resizable"] = false;
        $col["editable"] = false; // this column is editable
        $col["hidden"] = false;
        $col["viewable"] = true;
        $col["search"] = false;
        $col["sortable"] = false;
        $cols[] = $col;

        // set columns
        $col = array();
        $col["title"] = "Company Name"; // caption of column
        $col["name"] = "Company_Name";
        $col["dbname"] = "companies.Company_Name"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = true;
        $col["sortable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Fed ID"; // caption of column
        $col["name"] = "Company_Fed_ID";
        $col["dbname"] = "companies.Company_Fed_ID"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        // set columns
        $col = array();
        $col["title"] = "SSN"; // caption of column
        $col["name"] = "SSN";
        $col["dbname"] = "companies.SSN"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $col["sortable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Email"; // caption of column
        $col["name"] = "Email";
        $col["dbname"] = "companies.Email"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Business_NameW9"; // caption of column
        $col["name"] = "Business_NameW9";
        $col["dbname"] = "companies.Business_NameW9"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $cols[] = $col;

        // set columns
        $col = array();
        $col["title"] = "Client ID"; // caption of column
        $col["name"] = "Client_ID";
        $col["dbname"] = "clients.Client_ID"; // grid column name, same as db field or alias from sql
        $col["resizable"] = false;
        $col["editable"] = false; // this column is editable
        $col["hidden"] = false;
        $col["viewable"] = true;
        $col["search"] = false;
        $col["sortable"] = false;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Client Number"; // caption of column
        $col["name"] = "Client_Number";
        $col["dbname"] = "clients.Client_Number"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Client Logo Name"; // caption of column
        $col["name"] = "Client_Logo_Name";
        $col["dbname"] = "clients.Client_Logo_Name"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Client Approval Amount 1"; // caption of column
        $col["name"] = "Client_Approval_Amount_1";
        $col["dbname"] = "clients.Client_Approval_Amount_1"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Client Approval Amount 2"; // caption of column
        $col["name"] = "Client_Approval_Amount_2";
        $col["dbname"] = "clients.Client_Approval_Amount_2"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $cols[] = $col;

        // set columns
        $col = array();
        $col["title"] = "Address ID"; // caption of column
        $col["name"] = "Address_ID";
        $col["dbname"] = "addresses.Address_ID"; // grid column name, same as db field or alias from sql
        $col["resizable"] = false;
        $col["editable"] = false; // this column is editable
        $col["hidden"] = true;
        $col["viewable"] = true;
        $col["search"] = false;
        $col["sortable"] = false;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Address1"; // caption of column
        $col["name"] = "Address1";
        $col["dbname"] = "addresses.Address1"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Address2"; // caption of column
        $col["name"] = "Address2";
        $col["dbname"] = "addresses.Address2"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "City"; // caption of column
        $col["name"] = "City";
        $col["dbname"] = "addresses.City"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "State"; // caption of column
        $col["name"] = "State";
        $col["dbname"] = "addresses.State"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "ZIP"; // caption of column
        $col["name"] = "ZIP";
        $col["dbname"] = "addresses.ZIP"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Country"; // caption of column
        $col["name"] = "Country";
        $col["dbname"] = "addresses.Country"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Phone"; // caption of column
        $col["name"] = "Phone";
        $col["dbname"] = "addresses.Phone"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Fax"; // caption of column
        $col["name"] = "Fax";
        $col["dbname"] = "addresses.Fax"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $cols[] = $col;

        $g = new jqgrid();

        $grid["caption"] = "Clients";
       // $grid["multiselect"] = true;
        $grid["autowidth"] = true;
        $grid["resizable"] = true;
        //$grid["toppager"] = true;
        $grid["sortname"] = 'companies.Company_Name';
        $grid["sortorder"] = "ASC";
        $grid["add_options"] = array(
            'width'=>'420',
            "closeAfterEdit"=>true, // close dialog after add/edit
            "top"=>"200", // absolute top position of dialog
            "left"=>"200" // absolute left position of dialog
        );

        $g->set_options($grid);

        $g->set_actions(array(
                "add"=>false, // allow/disallow add
                "edit"=>true, // allow/disallow edit
                "delete"=>true, // allow/disallow delete
                "rowactions"=>true, // show/hide row wise edit/del/save option
                "export"=>true, // show/hide export to excel option
                "autofilter" => true, // show/hide autofilter for search
                "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
            )
        );

        $g->select_command = "SELECT  clients.Client_ID, clients.Client_Number, clients.Client_Logo_Name,
                                      companies.*, addresses.*, clients.Client_Approval_Amount_1,
                                      clients.Client_Approval_Amount_2
                              FROM clients
                              LEFT JOIN companies ON clients.Company_ID = companies.Company_ID
                              LEFT JOIN company_addresses ON company_addresses.Company_ID = companies.Company_ID
                              LEFT JOIN addresses ON addresses.Address_ID = company_addresses.Address_ID";

        // set database table for CRUD operations
        $g->table = "clients";

        $g->set_columns($cols);

        // group columns header
        $g->set_group_header( array(
                "useColSpanStyle"=>true,
                "groupHeaders"=>array(
                    array(
                        "startColumnName"=>'Company_ID', // group starts from this column
                        "numberOfColumns"=>6, // group span to next 2 columns
                        "titleText"=>'Company Information' // caption of group header
                    ),
                    array(
                        "startColumnName"=>'Client_ID', // group starts from this column
                        "numberOfColumns"=>5, // group span to next 2 columns
                        "titleText"=>'Client Information' // caption of group header
                    ),
                    array(
                        "startColumnName"=>'Address1', // group starts from this column
                        "numberOfColumns"=>8, // group span to next 2 columns
                        "titleText"=>"Company's Address" // caption of group header
                    )
                )
            )
        );

        // render grid and get html/js output
        $out = $g->render("Clients");

        $this->render('index',array(
            'out'=>$out,
        ));
	}
Exemplo n.º 10
0
    /**
     * Get count of documents in storage
     * @param $id
     * @param $rowType
     * @return mixed
     */
    public static function getDocumentsCount($id, $rowType)
    {
        $where = "(`ld`.`Access_Type` = '" . Storages::HAS_ACCESS . "' OR `ds`.`User_ID` = '" . Yii::app()->user->userID ."') ";
        $where .= " AND `st`.`Client_ID` = '" . Yii::app()->user->clientID ."' ";
        if (Yii::app()->user->projectID != 'all') {
            $where .= " AND `st`.`Project_ID` = '" . Yii::app()->user->projectID ."' ";
        }

        if ($rowType == 'storage') {
            $where .= " AND `st`.`Storage_ID` = '" . $id ."' ";
        } else if ($rowType == 'section') {
            $where .= " AND `sc`.`Section_ID` = '" .$id ."' ";
        } else {
            $where .= " AND `ss`.`Subsection_ID` = '" . $id ."' ";
        }

        if (Yii::app()->user->id == 'user') {
            $where .= " AND `ds`.`User_ID` = '" . Yii::app()->user->userID . "'";
        }

        $query = "SELECT count(*) as count
                  FROM `library_docs` as ld
                  LEFT JOIN `documents` as ds ON `ds`.`Document_ID` = `ld`.`Document_ID`
                  LEFT JOIN `subsections` as ss ON `ss`.`Subsection_ID` = `ld`.`Subsection_ID`
                  LEFT JOIN `sections` as sc ON `sc`.`Section_ID` = `ss`.`Section_ID`
                  LEFT JOIN `storages` as st ON `st`.`Storage_ID` = `sc`.`Storage_ID`
                  WHERE $where";

        $connection=Yii::app()->db;
        $command=$connection->createCommand($query);
        $row=$command->queryRow();
        $count = $row['count'];

        // add unassigned W9s of Vendor folder and W9 book binder
        if ($rowType == 'storage') {
            $storage = Storages::model()->findByPk($id);
            if ($storage->Storage_Type == Storages::SHELF) {
                $count += W9::getCountOfAvailableW9sOfYear($storage->Year);
            } else {
                $condition = new CDbCriteria();
                $condition->condition = "t.Storage_ID = '" . $id . "'";
                $condition->addCondition("t.Folder_Cat_ID = '" . self::VENDOR_DOCUMENTS . "'");
                $vendorFolders = Sections::model()->findAll($condition);
                foreach ($vendorFolders as $vendorFolder) {
                    $w9 = W9::getCompanyW9Doc($vendorFolder->Vendor_ID);
                    if ($w9) {
                        $count++;
                    }
                }
            }
        } else if ($rowType == 'section') {
            $section = Sections::model()->with('storage')->findByPk($id);
            if ($section->Folder_Cat_ID == self::W9_BOOK) {
                $count += W9::getCountOfAvailableW9sOfYear($section->storage->Year);
            } else if ($section->Folder_Cat_ID == self::VENDOR_DOCUMENTS) {
                $w9 = W9::getCompanyW9Doc($section->Vendor_ID);
                if ($w9) {
                    $count++;
                }
            }
        } else {
            $subsection = Subsections::model()->with('user', 'section.storage')->findByPk($id);
            if ($subsection->section->Folder_Cat_ID == self::W9_BOOK && $subsection->Created_By == 0) {
                $count += W9::getCountOfAvailableW9sOfYear($subsection->section->storage->Year);
            } else if ($subsection->section->Folder_Cat_ID == self::VENDOR_DOCUMENTS && $subsection->Created_By == 0) {
                $w9 = W9::getCompanyW9Doc($subsection->section->Vendor_ID);
                if ($w9) {
                    $count++;
                }
            }
        }


        return $count;
    }