public function Guardar() { if (empty($this->fv_error_message)) { foreach ($this->getMasterIds() as $master_id) { # code... $master = MasterDocument::find($master_id); $td = TypeDocument::createNew(); $td->account_id = $this->getAccountId(); $td->master_id = $master->id; $td->javascript_web = $master->javascript_web; $td->javascript_pos = $master->javascript_pos; $td->logo = $this->getLogo(); $td->save(); } $this->fv_error_message = "Registro Existoso"; return true; } return false; }
public function Actualizar() { if ($this->id) { if (empty($this->fv_error_message)) { $facturas = Invoice::where('branch_id', $this->id)->where('account_id', $this->account_id)->first(); //si no tienen facturas seguir if (!$facturas || true) { $usuarios = UserBranch::getUsersBranch($this->id, $this->account_id); // si no tiene usuarios asignados y no tiene facturas puede hacer los cambios --esto es para de baja necesito descansar XD // if(!$usuarios) // { $this->account_id = $this->account_id ? $this->account->id : $this->fv_account_id; $this->name = $this->fv_name; $this->number_branch = $this->fv_number_branch; $this->address2 = $this->fv_address2; $this->address1 = $this->fv_address1; $this->work_phone = $this->fv_workphone; $this->city = $this->fv_city; $this->state = $this->fv_state; $this->deadline = $this->fv_deadline; $this->key_dosage = $this->fv_key_dossage; $this->economic_activity = $this->fv_economic_activity; $this->number_process = $this->fv_number_process; $this->number_autho = $this->fv_nummber_autho; $this->law = $this->fv_law; $this->type_third = $this->getType_thrird(); $this->invoice_number_counter = 1; $this->save(); //verificar los nuevos asignados //aplicando algorimo de asignacion $type_branch = TypeDocumentBranch::where('branch_id', $this->id)->first(); $master = MasterDocument::find(1); if ($this->type_third != 2) { $type_branch->template = $master->javascript_web; } else { $type_branch->template = $master->javascript_pos; } $type_branch->save(); // foreach (TypeDocumentBranch::where('branch_id',$this->id)->get() as $type_document_branch) { // # code... // $type_document_branch->delete(); // } // foreach ($this->fv_type_documents_branch as $type_document_nuevos) // { // # code... // //TODO: acabar esta parte de la consulta me falta la asignacion XD ...... :() // $existeAsignado = TypeDocumentBranch::withTrashed()->where('branch_id',$this->id) // ->where('type_document_id',$type_document_nuevos)->first(); // if($existeAsignado) // { // $existeAsignado->restore(); // } // else // { // $tipo = new TypeDocumentBranch(); // $tipo->branch_id = $this->id; // $tipo->type_document_id = $type_document_nuevos; // $tipo->save(); // } // } $this->fv_error_message = "Registro Actualizado"; return true; // } // $this->fv_error_message = $this->fv_error_message . ' debe reasignar a los usuarios de esta sucursal <br>'; // return false; } //si tiene facturas hay que verificar la fecha actual sea mayor a la fecha limite $this->name = $this->fv_name; $this->address2 = $this->fv_address2; $this->address1 = $this->fv_address1; $this->work_phone = $this->fv_workphone; $this->city = $this->fv_city; $this->state = $this->fv_state; $fecha_actual = new DateTime("now"); $fecha_limite = new DateTime($this->deadline); if ($fecha_actual > $fecha_limite) { $this->number_branch = $this->fv_number_branch; //docificaciones y numero de invoicce nada masXD $this->deadline = $this->fv_deadline; $this->key_dosage = $this->fv_key_dossage; $this->economic_activity = $this->fv_economic_activity; $this->number_process = $this->fv_number_process; $this->number_autho = $this->fv_nummber_autho; $this->law = $this->fv_law; $this->type_third = $this->getType_thrird(); //colocamos la sucursal en 1 de nuevo $this->invoice_number_counter = 1; } $this->save(); //modificacion foreach (TypeDocumentBranch::where('branch_id', $this->id) as $type_document_branch) { # code... $type_document_branch->delete(); } foreach ($this->fv_type_documents_branch as $type_document_nuevos) { # code... //TODO: acabar esta parte de la consulta me falta la asignacion XD ...... :() $existeAsignado = TypeDocumentBranch::withTrashed()->where('branch_id', $this->id)->where('type_document_id', $type_document_nuevos)->first(); if ($existeAsignado) { $existeAsignado->restore(); } else { $tipo = new TypeDocumentBranch(); $tipo->branch_id = $this->id; $tipo->type_document_id = $type_document_nuevos; $tipo->save(); } } $this->fv_error_message = "Registro Actualizado"; return true; } } $this->fv_error_message = $this->fv_error_message . ' Sucursal ' . ERROR_NULL . '<br>'; return false; }