예제 #1
0
 public function view()
 {
     if (!isset($this->request->params['slug'])) {
         $this->notice('invalid');
     }
     $branch = $this->Branch->find('first', array('conditions' => array('Branch.slug' => $this->request->params['slug'], 'Branch.active' => 1), 'contain' => array('Address' => array('fields' => array('Address.address'), 'Country' => array('fields' => array('Country.name'))), 'Contact')));
     if (empty($branch)) {
         $this->notice(__('The branch does not exsit'), array('redirect' => true));
     }
     $this->set('title_for_layout', sprintf(__('Contact us at %s'), $branch['Branch']['name']));
     $this->set(compact('branch'));
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $student = Student::find($id);
     if ($student == NULL) {
         throw new Exception('Invalid Student ID');
     }
     $student->year = (int) substr($student->year, 2, 4);
     $student_category = StudentCategories::find($student->category);
     $student->category = $student_category->category;
     $student_branch = Branch::find($student->branch);
     $student->branch = $student_branch->branch;
     if ($student->rejected == 1) {
         unset($student->approved);
         unset($student->books_issued);
         $student->rejected = (bool) $student->rejected;
         return $student;
     }
     if ($student->approved == 0) {
         unset($student->rejected);
         unset($student->books_issued);
         $student->approved = (bool) $student->approved;
         return $student;
     }
     unset($student->rejected);
     unset($student->approved);
     $student_issued_books = Logs::select('book_issue_id', 'issued_at')->where('student_id', '=', $id)->orderBy('time_stamp', 'desc')->take($student->books_issued)->get();
     foreach ($student_issued_books as $issued_book) {
         $issue = Issue::find($issued_book->book_issue_id);
         $book = Books::find($issue->book_id);
         $issued_book->name = $book->title;
         $issued_book->issued_at = date('d-M', $issued_book->issued_at);
     }
     $student->issued_books = $student_issued_books;
     return $student;
 }
예제 #3
0
 public function UpdateListBranch()
 {
     $input = Input::all();
     $listBranchID = $input['update_list_branch_id'];
     $listBranchID = explode(",", $listBranchID);
     foreach ($listBranchID as $p) {
         if ($input['name'] != '') {
             $branch = Branch::find($p);
             $branch->name = $input['name'];
             $branch->save();
         }
     }
 }
예제 #4
0
 public static function aviso_renovar()
 {
     $fecha_i = date('Y-m-d');
     $fecha_f = Branch::find(Session::get('branch_id'))->deadline;
     $dias = (strtotime($fecha_f) - strtotime($fecha_i)) / 86400;
     if ($dias <= 5 && $dias >= 1) {
         $mensaje = '<span class="label label-warning pull-right">Fecha Límite de Emisión expirará en  ' . $dias . ' día(s).</span>';
         return $mensaje;
     } elseif ($dias == 0) {
         $mensaje = '<span class="label label-danger pull-right">Su Fecha Límite de Emisión Expira Hoy.</span>';
         return $mensaje;
     }
     return null;
 }
예제 #5
0
 public static function all($options = [])
 {
     $condition = (is_array($options) and $options['all']) ? '' : self::baseCondition();
     $list = Branch::find($condition);
     if ($list) {
         $list = $list->toArray();
         if (is_array($options) and $options['key']) {
             $data = [];
             foreach ($list as $row) {
                 $data[$row['bid']] = $row;
             }
             $list = $data;
         }
         return $list;
     }
     return [];
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $this->info('Search Delivery Items Life Time');
     // 六十天提醒
     //
     $N_Time = date("Y-m-d", time());
     $L_Time = date("Y-m-d", time() + 60 * 3600 * 24);
     // 获取满足条件的货品
     //
     $Items = DeliveryItems::where('life_date', '>', $N_Time)->where('life_date', '<', $L_Time)->orderBy('delivery_id', 'desc')->get();
     // 初始化
     //
     $branch_ids = array();
     $delivery_ids = array();
     foreach ($Items as $Item) {
         // 条件过滤
         //
         if (!in_array($Item->delivery_id, $delivery_ids) && in_array($Item->branch_id, $branch_ids)) {
             continue;
         } else {
             if (!in_array($Item->delivery_id, $delivery_ids)) {
                 $delivery_ids[] = $Item->delivery_id;
             }
             if (!in_array($Item->branch_id, $branch_ids)) {
                 $branch_ids[] = $Item->branch_id;
             }
             $branch = Branch::find($Item->branch_id);
             $delivery = Delivery::find($Item->delivery_id);
             if ($branch && $delivery) {
                 $notice = new Notice();
                 $notice->user_id = $branch->user_id;
                 $notice->type = '5';
                 $notice->content = '客户(' . $branch->name . ')的出货单(' . $delivery->bn . ')中商品(' . $Item->good_name . ')' . date("Y-m-d", strtotime($Item->life_date)) . ' 过期!';
                 $notice->data = json_encode(array('branch_id' => $Item->branch_id, 'delivery_id' => $Item->delivery_id));
                 $notice->read = '0';
                 $notice->timeline = date("Y-m-d H:i:s", time());
                 $notice->save();
                 $this->info($notice->content);
             }
         }
     }
     $this->info('Done!');
 }
예제 #7
0
파일: Ldap.php 프로젝트: knatorski/SMS
 /**
  * Implementacja metody z interfejsu Zend_Auth_Adapter_Interface
  * @see Zend_Auth_Adapter_Interface::authenticate()
  * @return Zend_Auth_Result
  */
 public function authenticate()
 {
     if (empty($this->_username)) {
         throw new Zend_Auth_Adapter_Exception('Nie podano loginu!');
     }
     if (empty($this->_password)) {
         throw new Zend_Auth_Adapter_Exception('Nie podano hasła!');
     }
     $config = Zend_Registry::get('config');
     $this->_options = $config['ldap'];
     $resultLDAP = parent::authenticate();
     if ($resultLDAP->isValid()) {
         $userModel = new User();
         $userRow = $userModel->fetchRow(array('login = ?' => new Zend_Db_Expr("UPPER('{$this->_username}')"), 'ghost = ?' => 'f', 'is_locked = ?' => 'f', new Zend_Db_Expr('valid_until > NOW()')));
         if ($userRow !== null) {
             $identity = $this->_toStdClass($userRow);
             unset($identity->password);
             $ldapData = parent::getAccountObject();
             $identity->ldap = $ldapData;
             $branchModel = new Branch();
             $identity->id_branch = ODDZIAL_ID;
             $identity->view_branch = ODDZIAL_ID;
             $data = $branchModel->find($identity->id_branch);
             $d = $data->current()->toArray();
             $d['application_code'] = 'getin';
             $identity->jednostka = $d;
             $identity->user_backend_apps_logins = null;
             $identity->default_branches[$d['application_code']]['default_login'] = '******';
             $this->_authResult['code'] = Zend_Auth_Result::SUCCESS;
             $this->_authResult['messages'] = 'Autoryzacja pomyślna.';
             $this->_authResult['identity'] = $identity;
             return $this->_createAuthResult();
         } else {
             $this->_authResult['code'] = Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND;
             $this->_authResult['messages'] = 'Konto nieaktywne lub zablokowane.';
             return $this->_createAuthResult();
         }
     } else {
         $this->_authResult['code'] = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID;
         $this->_authResult['messages'] = 'Nieprawidłowe dane logowania.';
         return $this->_createAuthResult();
     }
 }
예제 #8
0
 function _authenticateValidateResult($resultIdentity)
 {
     $zendAuthCredentialMatchColumn = $this->_zendDb->foldCase('zend_auth_credential_match');
     if ($resultIdentity[$zendAuthCredentialMatchColumn] != '1') {
         $this->_authenticateResultInfo['code'] = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID;
         $this->_authenticateResultInfo['messages'][] = 'Supplied credential is invalid.';
         return $this->_authenticateCreateAuthResult();
     }
     unset($resultIdentity[$zendAuthCredentialMatchColumn]);
     $this->_resultRow = $resultIdentity;
     // $userModel = new Logic_User();
     //  $user = $userModel->getUserByLogin();
     $userModel = new User();
     $user = $userModel->fetchRow(array('login = ?' => new Zend_Db_Expr("UPPER('" . $resultIdentity['login'] . "')"), 'ghost = ?' => 'f', 'is_locked = ?' => 'f', new Zend_Db_Expr('valid_until > NOW()')));
     if (empty($user)) {
         $this->_authenticateResultInfo['code'] = Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND;
         $this->_authenticateResultInfo['messages'][] = 'Authentication failed.';
         return $this->_authenticateCreateAuthResult();
     }
     $identity = $this->_toStdClass($user);
     $identity->password = $this->_password;
     $branchModel = new Branch();
     $identity->id_branch = ODDZIAL_ID;
     $identity->view_branch = ODDZIAL_ID;
     $data = $branchModel->find($identity->id_branch);
     $d = $data->current()->toArray();
     $d['application_code'] = 'getin';
     $identity->jednostka = $d;
     $identity->user_backend_apps_logins = null;
     $identity->default_branches[$d['application_code']]['default_login'] = '******';
     //$identity->user_backend_apps_logins[$d['application_code']]['application_login'] = '******';
     $this->_authenticateResultInfo['identity'] = $identity;
     $this->_resultRow = $user;
     $this->_authenticateResultInfo['code'] = Zend_Auth_Result::SUCCESS;
     $this->_authenticateResultInfo['messages'][] = 'Authentication successful.';
     return $this->_authenticateCreateAuthResult();
 }
예제 #9
0
 private function saveLote($factura)
 {
     $account = DB::table('accounts')->where('id', '=', Auth::user()->account_id)->first();
     $branch = Branch::find(Session::get('branch_id'));
     // return $factura['nit'];
     $client = Client::where('account_id', '=', Auth::user()->account_id)->where('public_id', $factura['id'])->first();
     //if(!$client)
     //   return $factura['nit'];
     $invoice = Invoice::createNew();
     $invoice->setPublicNotes($factura['nota']);
     $invoice->setBranch(Session::get('branch_id'));
     $invoice->setInvoiceDate(date("Y-m-d"));
     $invoice->setClient($client->id);
     $invoice->setEconomicActivity($branch->economic_activity);
     $invoice->setDiscount(0);
     $invoice->setClientName($client->name);
     $invoice->setClientNit($client->nit);
     $invoice->setUser(Auth::user()->id);
     //$date=date("Y-m-d",strtotime(Input::get('invoice_date')));
     //$invoice->setInvoiceDate($date);
     $total_cost = 0;
     foreach ($factura['products'] as $producto) {
         //$pr = Product::where('account_id',Auth::user()->account_id)->where('product_key',$producto['product_key'])->first();
         //$total_cost+= $pr->cost*$producto['qty'];
         $total_cost += $producto['cost'];
     }
     $invoice->importe_neto = trim($total_cost);
     $invoice->importe_total = trim($total_cost);
     //$invoice->note = trim(Input::get('nota'));
     $invoice->setAccountName($account->name);
     $invoice->setAccountNit($account->nit);
     $invoice->setBranchName($branch->name);
     $invoice->setAddress1($branch->address1);
     $invoice->setAddress2($branch->address2);
     $invoice->setPhone($branch->work_phone);
     $invoice->setCity($branch->city);
     $invoice->setState($branch->state);
     $invoice->setNumberAutho($branch->number_autho);
     $invoice->setKeyDosage($branch->key_dosage);
     $invoice->setTypeThird($branch->type_third);
     $invoice->setDeadline($branch->deadline);
     $invoice->setLaw($branch->law);
     $type_document = TypeDocument::where('account_id', Auth::user()->account_id)->first();
     $invoice->invoice_number = branch::getInvoiceNumber();
     $numAuth = $invoice->number_autho;
     $numfactura = $invoice->invoice_number;
     $nit = $invoice->client_nit;
     $fechaEmision = date("Ymd", strtotime($invoice->invoice_date));
     $total = $invoice->importe_neto;
     $llave = $branch->key_dosage;
     $codigoControl = Utils::getControlCode($numfactura, $nit, $fechaEmision, $total, $numAuth, $llave);
     $invoice->setControlCode($codigoControl);
     $documents = TypeDocumentBranch::where('branch_id', $invoice->branch_id)->orderBy('id', 'ASC')->get();
     foreach ($documents as $document) {
         $actual_document = TypeDocument::where('id', $document->type_document_id)->first();
         if ($actual_document->master_id == 1) {
             $id_documento = $actual_document->id;
         }
     }
     $invoice->setJavascript($id_documento);
     $invoice->logo = 1;
     $invoice->sfc = $branch->sfc;
     //$invoice->qr =$invoice->account_nit.'|'.$invoice->invoice_number.'|'.$invoice->number_autho.'|'.$invoice->invoice_date.'|'.$invoice->importe_neto.'|'.$invoice->importe_total.'|'.$invoice->client_nit.'|'.$invoice->importe_ice.'|0|0|'.$invoice->descuento_total;
     if ($account->is_uniper) {
         $invoice->account_uniper = $account->uniper;
     }
     //$invoice->logo = $type_document->logo;
     $invoice->save();
     foreach ($factura['products'] as $producto) {
         $product = Product::where('account_id', Auth::user()->account_id)->where('product_key', $producto['product_key'])->first();
         if ($product != null) {
             $invoiceItem = InvoiceItem::createNew();
             $invoiceItem->setInvoice($invoice->id);
             $invoiceItem->setProduct($product->id);
             $invoiceItem->setProductKey($product->product_key);
             $invoiceItem->setNotes($product->notes . " " . $producto['description']);
             $invoiceItem->setCost($producto['cost']);
             $invoiceItem->setQty(1);
             $invoiceItem->save();
         }
     }
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $issue = Issue::find($id);
     if ($issue == NULL) {
         throw new Exception('Invalid Book ID');
     }
     $issue->added_at_timestamp = date('d-M-y h:i A', strtotime($issue->added_at_timestamp));
     $book = Books::find($issue->book_id);
     $issue->book_name = $book->title;
     $issue->author = $book->author;
     $issue->category = Categories::find($book->category_id)->category;
     $issue->available_status = (bool) $issue->available_status;
     if ($issue->available_status == 1) {
         return $issue;
     }
     $conditions = array('return_time' => 0, 'book_issue_id' => $id);
     $book_issue_log = Logs::where($conditions)->take(1)->get();
     foreach ($book_issue_log as $log) {
         $student_id = $log->student_id;
     }
     $student_data = Student::find($student_id);
     unset($student_data->email_id);
     unset($student_data->books_issued);
     unset($student_data->approved);
     unset($student_data->rejected);
     $student_branch = Branch::find($student_data->branch)->branch;
     $roll_num = $student_data->roll_num . '/' . $student_branch . '/' . substr($student_data->year, 2, 4);
     unset($student_data->roll_num);
     unset($student_data->branch);
     unset($student_data->year);
     $student_data->roll_num = $roll_num;
     $student_data->category = StudentCategories::find($student_data->category)->category;
     $issue->student = $student_data;
     return $issue;
 }
예제 #11
0
                    <!--
                    <td>
                        <?php 
if ($user->branch_id) {
    $branch = Branch::find($user->branch_id);
    if ($branch) {
        echo $branch->name;
    }
}
?>
                    </td>
                    -->
                    <td>
                        <?php 
if ($user->branch_id) {
    $branch = Branch::find($user->branch_id);
    if ($branch && isset($branch->brand_id) && $branch->brand_id) {
        $brand = Brand::find($branch->brand_id);
        if ($brand) {
            echo $brand->name;
        }
    }
}
?>
                    </td>
                    <td>
                        {{ $user->isActivated() ? trans('core::all.yes') : trans('core::all.no') }}
                    </td>
                    <td class="center" width="100">
                        <div>
                            @if($currentUser->hasAccess('update-user-info'))
예제 #12
0
 public function getRecoverCapsuleList($BranchId, $GoodId)
 {
     $capsule = GoodCapsule::where('branch_id', $BranchId)->where('good_id', $GoodId)->orderBy('created_at', 'desc')->paginate();
     return View::make('branch.recover-capsule-list')->with('branch', Branch::find($BranchId))->with('capsule', $capsule);
 }
예제 #13
0
 public function getWarehouseSelect($BranchId)
 {
     $branch = Branch::find($BranchId);
     $warehouse = Warehouse::all();
     return View::make('picking.warehouse-select')->with(compact('warehouse'))->with(compact('branch'));
 }
예제 #14
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     if (Auth::user()->is_admin) {
         $branch = Branch::find($id);
         if ($branch->number_branch != 0) {
             $branch->delete();
             Session::flash('message', 'Se elimino satisfactoriamente a la sucursal');
         } else {
             Session::flash('error', 'No se puede eliminar a la casa matriz ');
         }
         return Redirect::to('sucursales');
     }
     return Redirect::to('inicio');
 }
예제 #15
0
 public static function GetByAddress($branchAddress)
 {
     return Branch::find(array('address' => $branchAddress));
 }
예제 #16
0
파일: branch.php 프로젝트: pamalite/yel
print_r(Branch::getCurrency('1'));
echo '</pre>';
?>
<p style="font-weight: bold;">Update</p><p><?php 
$data = array();
$data['id'] = '2';
$data['address'] = "Suite 3, 22 Council St,\nHawthorn East";
$data['state'] = "Victoria";
$data['zip'] = "3123";
$data['country'] = 'AU';
$data['phone'] = '+61 03 9882 7164';
$data['fax'] = '+61 03 9882 9792';
?>
Before...<?php 
echo '<pre>';
print_r(Branch::get('2'));
echo '</pre>';
Branch::update($data);
?>
After...<?php 
echo '<pre>';
print_r(Branch::get('2'));
echo '</pre>';
?>
<p style="font-weight: bold;">Find</p><p><?php 
$criteria = array('columns' => 'branches.branch, branches.address, branches.zip, branches.state, countries.country', 'match' => 'branches.phone LIKE \'%6363\'', 'joins' => 'countries ON countries.country_code = branches.country');
echo '<pre>';
print_r(Branch::find($criteria));
echo '</pre>';
?>
</p>
예제 #17
0
 public function asignarSucursal()
 {
     if (Session::has('branch_id')) {
         Session::forget('branch_id');
         Session::forget('branch_name');
     }
     // Session::forget('branch_id');
     Session::put('branch_id', Input::get('branch_id'));
     $sucursal = Branch::find(Session::get('branch_id'));
     Session::put('branch_name', $sucursal->name);
     // return Response::json(array('info  ' =>$sucursal));
     return Redirect::to('inicio');
 }
예제 #18
0
 private function saveOfflineInvoice2($factura)
 {
     // return Response::json($factura);
     $input = $factura;
     //print_r($input->invoice_number);
     //return ;
     // $invoice_number = Auth::user()->account->getNextInvoiceNumber();
     //$invoice_number = (int)Auth::user()->branch->getNextInvoiceNumber();
     //$numero =(int) $input['invoice_number'];
     $numero = (int) $input->invoice_number;
     $user_branch = UserBranch::where('user_id', Auth::user()->id)->first();
     $sucursal = Branch::find($user_branch->branch_id);
     //$sucursal->invoice_number_counter=  $input['invoice_number']+1;
     $sucursal->invoice_number_counter = $input->invoice_number + 1;
     $sucursal->save();
     $invoice_number = $numero;
     // $numero =(int)  $input['invoice_number'];
     // if($invoice_number!=$numero)
     // {
     // 	return Response::json( array('resultado' => '1' ,'invoice_number'=>$invoice_number));
     // }
     //$client_id = $input['client_id'];
     $client_id = $input->client_id;
     // $client = DB::table('clients')->select('id','nit','name','public_id')->where('id',$input['client_id'])->first();
     // $user_id = Auth::user()->getAuthIdentifier();
     $user = DB::table('users')->select('account_id', 'price_type_id')->where('id', Auth::user()->id)->first();
     //$account_id = $user->account_id;
     // $account = DB::table('accounts')->select('num_auto','llave_dosi','fecha_limite')->where('id',$user->account_id)->first();
     //$branch = DB::table('branches')->select('num_auto','llave_dosi'	,'fecha_limite','address1','address2','country_id','industry_id')->where('id',$user['branch_id'])->first();
     //$branch = DB::table('branches')->select('num_auto','llave_dosi','fecha_limite','address1','address2','country_id','industry_id')->where('id','=',$user->branch_id)->first();
     // $branch = DB::table('branches')->select('number_autho','key_dosage','deadline','address1','address2','country_id','industry_id','law','activity_pri','activity_sec1','name')->where('id','=',$user->branch_id)->first();
     $branch = DB::table('branches')->where('id', '=', $user_branch->branch_id)->first();
     //$items = $input['invoice_items'];
     $items = $input->invoice_items;
     // echo "this is initializioinh";
     // print_r($input->invoice_items);
     // return 0;
     // $linea ="";
     $amount = 0;
     $subtotal = 0;
     $fiscal = 0;
     $icetotal = 0;
     $bonidesc = 0;
     foreach ($items as $item) {
         # code...
         //$product_id = $item['id'];
         $product_id = $item->id;
         $pr = DB::table('products')->join('prices', "product_id", "=", 'products.id')->select('products.id', 'products.notes', 'prices.cost', 'products.ice', 'products.units', 'products.cc')->where('prices.price_type_id', '=', $user->price_type_id)->where('products.account_id', '=', $user->account_id)->where('products.id', "=", $product_id)->first();
         // $pr = DB::table('products')->select('cost')->where('id',$product_id)->first();
         //$qty = (int) $item['qty'];
         $qty = (int) $item->qty;
         $cost = $pr->cost / $pr->units;
         $st = $cost * $qty;
         $subtotal = $item->subtotal;
         //$subtotal + $st;
         //$bd= ($item['boni']*$cost) + $item['desc'];
         $bd = $item->boni * $cost + $item->desc;
         $bonidesc = $bonidesc + $bd;
         $amount = $amount + $st - $bd;
         $icetotal = $pr->ice;
         /*$ice = DB::table('tax_rates')->select('rate')->where('name','=','ICE')->first();
         		if($pr->ice == 1)
         		{
         			
         			//caluclo ice bruto 
         			$iceBruto = ($qty *($pr->cc/1000)*$ice->rate);
         			//$iceNeto = (((int)$item['boni']) *($pr->cc/1000)*$ice->rate);
         			$iceNeto = (((int)$item->boni) *($pr->cc/1000)*$ice->rate);
         			$icetotal = $icetotal +($iceBruto-$iceNeto) ;
         			// $fiscal = $fiscal + ($amount - ($item['qty'] *($pr->cc/1000)*$ice->rate) );
         		}
         		*/
     }
     //$fiscal = $amount -$bonidesc-$icetotal;
     $fiscal = $subtotal - $bonidesc - $icetotal;
     $balance = $amount;
     /////////////////////////hasta qui esta bien al parecer hacer prueba de que fuciona el join de los productos XD
     $invoice_dateCC = date("Ymd");
     $invoice_date = date("Y-m-d", strtotime($input->fecha));
     $invoice_date_limitCC = date("Y/m/d", strtotime($branch->deadline));
     $cod_control = $input->cod_control;
     $ice = DB::table('tax_rates')->select('rate')->where('name', '=', 'ice')->first();
     //
     // creando invoice
     $cuenta = Account::find(1);
     $invoice = Invoice::createNew();
     $invoice->invoice_number = $invoice_number;
     $invoice->client_id = $client_id;
     $invoice->user_id = Auth::user()->id;
     $invoice->account_id = Auth::user()->account_id;
     $invoice->branch_id = $user_branch->branch_id;
     $invoice->importe_neto = number_format((double) $amount, 2, '.', '');
     $invoice->importe_total = $subtotal;
     $invoice->debito_fiscal = $fiscal;
     $invoice->law = $branch->law;
     $invoice->balance = $balance;
     $invoice->control_code = $cod_control;
     $invoice->start_date = $invoice_date;
     $invoice->invoice_date = $invoice_date;
     $invoice->economic_activity = $branch->economic_activity;
     // $invoice->activity_sec1=$branch->activity_sec1;
     // $invoice->invoice
     $invoice->end_date = $invoice_date_limitCC;
     //datos de la empresa atra vez de una consulta XD
     /*****************error generado al intentar guardar **/
     $invoice->branch_name = $branch->name;
     $invoice->address1 = $branch->address1;
     $invoice->address2 = $branch->address2;
     $invoice->number_autho = $branch->number_autho;
     $invoice->phone = $branch->work_phone;
     $invoice->city = $branch->city;
     $invoice->state = $branch->state;
     $invoice->account_name = $cuenta->name;
     $invoice->account_nit = $cuenta->nit;
     $invoice->importe_ice = $icetotal;
     $invoice->qr = $invoice->account_nit . '|' . $invoice->invoice_number . '|' . $invoice->number_autho . '|' . $invoice->invoice_date . '|' . $invoice->importe_neto . '|' . $invoice->importe_total . '|' . $invoice->client_nit . '|' . $invoice->importe_ice . '|0|0|' . $invoice->descuento_total;
     $invoice->key_dosage = $branch->key_dosage;
     $invoice->deadline = $branch->deadline;
     // $invoice->ice = $ice->rate;
     //cliente
     //$invoice->client_nit=$input['nit'];
     $invoice->client_nit = $input->nit;
     ///$invoice->client_name =$input['name'];
     $invoice->client_name = $input->name;
     $documents = TypeDocumentBranch::where('branch_id', $invoice->branch_id)->orderBy('id', 'ASC')->get();
     foreach ($documents as $document) {
         $actual_document = TypeDocument::where('id', $document->type_document_id)->first();
         if ($actual_document->master_id == 1) {
             $id_documento = $actual_document->id;
         }
     }
     $invoice->setJavascript($id_documento);
     $invoice->logo = 0;
     $account = Auth::user()->account;
     $invoice->save();
     foreach ($items as $item) {
         $product_id = $item->id;
         $product = DB::table('products')->join('prices', "product_id", "=", 'products.id')->select('products.id', 'products.notes', 'prices.cost', 'products.ice', 'products.units', 'products.cc', 'products.product_key')->where('prices.price_type_id', '=', $user->price_type_id)->where('products.account_id', '=', $user->account_id)->where('products.id', "=", $product_id)->first();
         $cost = $product->cost / $product->units;
         //$line_total= ((int)$item['qty'])*$cost;
         $line_total = (int) $item->qty * $cost;
         $invoiceItem = InvoiceItem::createNew();
         // $invoiceItem->invoice_id = $invoice->id;
         $invoiceItem->invoice_id = $invoice->id;
         $invoiceItem->product_id = $product_id;
         $invoiceItem->product_key = $product->product_key;
         $invoiceItem->notes = $product->notes;
         $invoiceItem->cost = $cost;
         $invoiceItem->boni = (int) $item->boni;
         $invoiceItem->discount = $item->desc;
         $invoiceItem->qty = (int) $item->qty;
         $invoiceItem->ice = $item->ice;
         $invoiceItem->subtotal = $item->subtotal;
         $invoiceItem->save();
     }
     $datos = array('resultado ' => "0");
 }
예제 #19
0
 public function asignarSucursal()
 {
     if (Session::has('branch_id')) {
         Session::forget('branch_id');
         Session::forget('branch_name');
         Session::forget('printer');
         Session::forget('printer');
         Session::forget('invoice_link');
     }
     // Session::forget('branch_id');
     Session::put('branch_id', Input::get('branch_id'));
     $sucursal = Branch::find(Session::get('branch_id'));
     Session::put('branch_name', $sucursal->name);
     Session::put('printer', Input::get('printer'));
     $documents = TypeDocumentBranch::where('branch_id', Input::get('branch_id'))->orderBy('id', 'ASC')->get();
     foreach ($documents as $document) {
         $actual_document = TypeDocument::where('id', $document->type_document_id)->first();
         if ($actual_document->master_id == 1 || $actual_document->master_id == 3) {
             $id_documento = $actual_document;
         }
     }
     switch ($id_documento->master_id) {
         case 1:
             Session::put('invoice_link', 'factura/create');
             break;
         case 3:
             Session::put('invoice_link', 'sinCreditoFiscal');
             break;
     }
     // return Response::json(array('info  ' =>$sucursal));
     return Redirect::to('inicio');
 }
예제 #20
0
 /**
  * Show the form for editing the specified branch.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $branch = Branch::find($id);
     return View::make('branches.edit', compact('branch'));
 }
예제 #21
0
 private function saveLote2($factura, $date)
 {
     //print_r($factura);
     //return;
     $account = DB::table('accounts')->where('id', '=', Auth::user()->account_id)->first();
     $branch = Branch::find(Session::get('branch_id'));
     $client = Client::where('account_id', '=', Auth::user()->account_id)->where('name', $factura['name'])->where('nit', $factura['nit'])->first();
     if (!$client) {
         ///echo "creo";
         $client = Client::createNew();
         $client->setNit(trim($factura['nit']));
         $client->setName(trim($factura['name']));
         $client->setBussinesName(trim($factura['razon']));
         $alt = $client->guardar();
         $client->save();
     }
     $invoice = Invoice::createNew();
     $invoice->setPublicNotes("");
     $invoice->setBranch(Session::get('branch_id'));
     $dateparser = explode("/", $date);
     $date = $dateparser[2] . '-' . $dateparser[1] . '-' . $dateparser[0];
     $invoice->setInvoiceDate($date);
     $invoice->setClient($client->id);
     $invoice->setEconomicActivity($branch->economic_activity);
     $invoice->setDiscount(0);
     $invoice->setClientName($client->business_name);
     $invoice->setClientNit($client->nit);
     $invoice->setUser(Auth::user()->id);
     $total_cost = 0;
     /*foreach ($factura['products'] as $producto)
       {
           $total_cost+= $producto['cost'];
       }*/
     $invoice->importe_neto = $factura['total'] * $factura['qty'];
     $invoice->importe_total = $factura['total'] * $factura['qty'];
     $invoice->debito_fiscal = $factura['total'] * $factura['qty'];
     //$invoice->note = trim(Input::get('nota'));
     $invoice->setAccountName($account->name);
     $invoice->setAccountNit($account->nit);
     $invoice->setBranchName($branch->name);
     $invoice->setAddress1($branch->address1);
     $invoice->setAddress2($branch->address2);
     $invoice->setPhone($branch->work_phone);
     $invoice->setCity($branch->city);
     $invoice->setState($branch->state);
     $invoice->setNumberAutho($branch->number_autho);
     $invoice->setKeyDosage($branch->key_dosage);
     $invoice->setTypeThird($branch->type_third);
     $invoice->setDeadline($branch->deadline);
     $invoice->setLaw($branch->law);
     $type_document = TypeDocument::where('account_id', Auth::user()->account_id)->firstOrFail();
     $invoice->invoice_number = branch::getInvoiceNumber();
     $numAuth = $invoice->number_autho;
     $numfactura = $invoice->invoice_number;
     $nit = $invoice->client_nit;
     $fechaEmision = date("Ymd", strtotime($invoice->invoice_date));
     $total = $invoice->importe_neto;
     $llave = $branch->key_dosage;
     $totalc = number_format((double) $total, 2, '.', '');
     if ($account->currency_id == 2) {
         $totalc = $total * $account->exchange;
         $totalc = number_format((double) $totalc, 2, '.', '');
     }
     $codigoControl = Utils::getControlCode($numfactura, $nit, $fechaEmision, $totalc, $numAuth, $llave);
     $invoice->setControlCode($codigoControl);
     $documents = TypeDocumentBranch::where('branch_id', $invoice->branch_id)->orderBy('id', 'ASC')->get();
     foreach ($documents as $document) {
         $actual_document = TypeDocument::where('id', $document->type_document_id)->first();
         if ($actual_document->master_id == 1) {
             $id_documento = $actual_document->id;
         }
     }
     $invoice->setJavascript($id_documento);
     $invoice->logo = 1;
     //$invoice->sfc = $branch->sfc;
     if ($account->currency_id == 1) {
         $invoice->sfc = 1;
     } else {
         $invoice->sfc = $account->exchange;
     }
     $invoice->qr = $invoice->account_nit . '|' . $invoice->invoice_number . '|' . $invoice->number_autho . '|' . $invoice->invoice_date . '|' . $invoice->importe_neto . '|' . $invoice->importe_total . '|' . $invoice->client_nit . '|' . $invoice->importe_ice . '|0|0|' . $invoice->descuento_total;
     if ($account->is_uniper) {
         $invoice->account_uniper = $account->uniper;
     }
     //$invoice->logo = $type_document->logo;
     $invoice->save();
     //foreach ($factura['products']  as $producto)
     //{
     $product = Product::where('account_id', Auth::user()->account_id)->where('product_key', $factura['code'])->first();
     if ($product != null) {
         $invoiceItem = InvoiceItem::createNew();
         $invoiceItem->setInvoice($invoice->id);
         $invoiceItem->setProduct($product->id);
         $invoiceItem->setProductKey($product->product_key);
         $invoiceItem->setNotes($product->notes);
         //$invoiceItem->setCost($factura['total']);
         $invoiceItem->setCost($factura['total']);
         $invoiceItem->setQty($factura['qty']);
         $invoiceItem->save();
     }
     // $this->sendInvoiceByMailLocal($client->name,$client->business_name,$invoice->id,$invoice->invoice_date,$client->nit);
     //}
 }
예제 #22
0
 public function obtenerFactura($public_id)
 {
     $client = DB::table('clients')->select('id', 'name', 'business_name', 'nit', 'public_id', 'custom_value4')->where('account_id', Auth::user()->account_id)->where('public_id', $public_id)->first();
     if ($client == null) {
         $datos = array('resultado' => 1, 'mensaje' => 'cliente no encontrado');
         return Response::json($datos);
     }
     //caso contrario tratar al cliente
     // $branch = Auth::user()->branch;
     $invoices = DB::table('invoices')->where('client_id', '=', $client->id)->orderBy('public_id')->get(array('id', 'invoice_number'));
     if ($invoices == null) {
         $datos = array('resultado' => 2, 'mensaje' => 'Cliente no emitio ninguna factura');
         return Response::json($datos);
     }
     $inv = "";
     foreach ($invoices as $invo) {
         $inv = $invo;
     }
     $invoice = DB::table('invoices')->where('id', '=', $inv->id)->first();
     $invoiceItems = DB::table('invoice_items')->select('notes', 'cost', 'qty')->where('invoice_id', '=', $invoice->id)->get(array('notes', 'cost', 'qty'));
     // $date = date_create($invoice->deadline);
     $date = new DateTime($invoice->deadline);
     $fecha_emision = new DateTime($invoice->invoice_date);
     // $account = DB::table('accounts')->select('name','nit')->where('id',$user->account_id)->first();
     $branch = Branch::find($invoice->branch_id);
     $account = array('name' => $invoice->account_name, 'nit' => $invoice->account_nit);
     $client->name = $invoice->client_name;
     $client->business_name = $invoice->client_name;
     $client->nit = $invoice->client_nit;
     $ice = $invoice->amount - $invoice->fiscal;
     $cliente = array('name' => $invoice->client_name, 'nit' => $invoice->client_nit);
     $factura = array('resultado' => 0, 'activity_pri' => $branch->economic_activity, 'invoice_number' => $invoice->invoice_number, 'control_code' => $invoice->control_code, 'invoice_date' => $fecha_emision->format('d/m/Y'), 'amount' => number_format((double) $invoice->importe_total, 2, '.', ''), 'subtotal' => number_format((double) $invoice->importe_neto, 2, '.', ''), 'fiscal' => number_format((double) $invoice->fiscal, 2, '.', ''), 'client' => $client, 'account' => $account, 'law' => $invoice->law, 'invoice_items' => $invoiceItems, 'address1' => $invoice->address1, 'address2' => $invoice->address2, 'num_auto' => $invoice->number_autho, 'fecha_limite' => $date->format('d/m/Y'));
     //its work ok go  get the money
     return Response::json($factura);
 }
 public function delete_branch()
 {
     $getID = Input::get('deleteID');
     $branch = Branch::find($getID);
     $branch->actStatus = '0';
     $branch->save();
     return Redirect::to('/branches');
 }