añadido mensaje en comentarios logistica para tirada flexible

This commit is contained in:
2025-05-26 20:23:15 +02:00
parent 981eb30c02
commit 43e0ced1bd
4 changed files with 142 additions and 86 deletions

View File

@ -12,7 +12,7 @@ use Hermawan\DataTables\DataTable;
use CodeIgniter\I18n\Time; use CodeIgniter\I18n\Time;
class Pedido extends \App\Controllers\BaseResourceController class Pedido extends \App\Controllers\BaseResourceController
{ {
protected $modelName = PedidoModel::class; protected $modelName = PedidoModel::class;
protected $format = 'json'; protected $format = 'json';
@ -29,9 +29,9 @@ class Pedido extends \App\Controllers\BaseResourceController
{ {
$this->viewData['pageTitle'] = lang('Pedidos.moduleTitle'); $this->viewData['pageTitle'] = lang('Pedidos.moduleTitle');
// Se indica que este controlador trabaja con soft_delete // Se indica que este controlador trabaja con soft_delete
$this->viewData = ['usingServerSideDataTable' => true]; $this->viewData = ['usingServerSideDataTable' => true];
// Breadcrumbs // Breadcrumbs
$this->viewData['breadcrumb'] = [ $this->viewData['breadcrumb'] = [
['title' => lang("App.menu_pedidos"), 'route' => "javascript:void(0);", 'active' => false], ['title' => lang("App.menu_pedidos"), 'route' => "javascript:void(0);", 'active' => false],
@ -169,7 +169,7 @@ class Pedido extends \App\Controllers\BaseResourceController
public function todos() public function todos()
{ {
$viewData = [ $viewData = [
'currentModule' => static::$controllerSlug, 'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Pedidos.pedido')]), 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Pedidos.pedido')]),
@ -195,21 +195,23 @@ class Pedido extends \App\Controllers\BaseResourceController
} }
public function cambiarEstado(){ public function cambiarEstado()
if($this->request->isAJAX()){ {
if ($this->request->isAJAX()) {
$id = $this->request->getPost('id'); $id = $this->request->getPost('id');
$estado = $this->request->getPost('estado'); $estado = $this->request->getPost('estado');
$this->model->where('id', $id)->set(['estado' => $estado])->update(); $this->model->where('id', $id)->set(['estado' => $estado])->update();
return $this->respond(['status' => 'success', 'message' => lang('Basic.global.success')]); return $this->respond(['status' => 'success', 'message' => lang('Basic.global.success')]);
}else{ } else {
return $this->failUnauthorized('Invalid request', 403); return $this->failUnauthorized('Invalid request', 403);
} }
} }
public function update($id = null){ public function update($id = null)
{
$data = []; $data = [];
@ -217,7 +219,7 @@ class Pedido extends \App\Controllers\BaseResourceController
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
if ($id == null) : if ($id == null):
$data = [ $data = [
'error' => 2, 'error' => 2,
$csrfTokenName => $newTokenHash $csrfTokenName => $newTokenHash
@ -227,7 +229,7 @@ class Pedido extends \App\Controllers\BaseResourceController
$id = filter_var($id, FILTER_SANITIZE_URL); $id = filter_var($id, FILTER_SANITIZE_URL);
$pedidoEntity = $this->model->find($id); $pedidoEntity = $this->model->find($id);
if ($pedidoEntity == false) : if ($pedidoEntity == false):
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Pedidos.pedido')), $id]); $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Pedidos.pedido')), $id]);
$data = [ $data = [
'error' => $message, 'error' => $message,
@ -236,19 +238,19 @@ class Pedido extends \App\Controllers\BaseResourceController
return $this->respond($data); return $this->respond($data);
endif; endif;
if ($this->request->getPost()) : if ($this->request->getPost()):
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
foreach(array_keys($sanitizedData) as $key){ foreach (array_keys($sanitizedData) as $key) {
if(str_starts_with($key, "fecha_")){ if (str_starts_with($key, "fecha_")) {
$sanitizedData[$key . "_change_user_id"] = $sanitizedData[$key . "_change_user_id"] =
auth()->user()->id; auth()->user()->id;
$data[$key . "_change_user"] = $data[$key . "_change_user"] =
model('App\Models\Usuarios\UserModel')->getFullName(auth()->user()->id); model('App\Models\Usuarios\UserModel')->getFullName(auth()->user()->id);
} }
} }
@ -256,9 +258,9 @@ class Pedido extends \App\Controllers\BaseResourceController
$sanitizedData['user_updated_id'] = auth()->user()->id; $sanitizedData['user_updated_id'] = auth()->user()->id;
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()): // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) : if ($this->canValidate()):
try { try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData); $successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) { } catch (\Exception $e) {
@ -274,7 +276,7 @@ class Pedido extends \App\Controllers\BaseResourceController
$pedidoEntity->fill($sanitizedData); $pedidoEntity->fill($sanitizedData);
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult):
$id = $pedidoEntity->id ?? $id; $id = $pedidoEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.'; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
@ -291,39 +293,39 @@ class Pedido extends \App\Controllers\BaseResourceController
$csrfTokenName => $newTokenHash $csrfTokenName => $newTokenHash
]; ];
return $this->respond($data); return $this->respond($data);
} } else {
else {
return $this->failUnauthorized('Invalid request', 403); return $this->failUnauthorized('Invalid request', 403);
} }
} }
public function edit($id=null){ public function edit($id = null)
{
if ($id == null) :
if ($id == null):
return $this->redirect2listView(); return $this->redirect2listView();
endif; endif;
$id = filter_var($id, FILTER_SANITIZE_URL); $id = filter_var($id, FILTER_SANITIZE_URL);
$pedidoEntity = $this->model->find($id); $pedidoEntity = $this->model->find($id);
if ($pedidoEntity == false) : if ($pedidoEntity == false):
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Pedidos.pedido')), $id]); $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Pedidos.pedido')), $id]);
return $this->redirect2listView('sweet-error', $message); return $this->redirect2listView('sweet-error', $message);
endif; endif;
$this->obtenerDatosFormulario($pedidoEntity); $this->obtenerDatosFormulario($pedidoEntity);
$pedidoEntity->fecha_entrega_real_change_user = $pedidoEntity->fecha_entrega_real_change_user_id?model('App\Models\Usuarios\UserModel')-> $pedidoEntity->fecha_entrega_real_change_user = $pedidoEntity->fecha_entrega_real_change_user_id ? model('App\Models\Usuarios\UserModel')->
getFullName($pedidoEntity->fecha_entrega_real_change_user_id):""; getFullName($pedidoEntity->fecha_entrega_real_change_user_id) : "";
$pedidoEntity->fecha_impresion_change_user = $pedidoEntity->fecha_impresion_change_user_id?model('App\Models\Usuarios\UserModel')-> $pedidoEntity->fecha_impresion_change_user = $pedidoEntity->fecha_impresion_change_user_id ? model('App\Models\Usuarios\UserModel')->
getFullName($pedidoEntity->fecha_impresion_change_user_id):""; getFullName($pedidoEntity->fecha_impresion_change_user_id) : "";
$pedidoEntity->fecha_encuadernado_change_user = $pedidoEntity->fecha_encuadernado_change_user_id?model('App\Models\Usuarios\UserModel')-> $pedidoEntity->fecha_encuadernado_change_user = $pedidoEntity->fecha_encuadernado_change_user_id ? model('App\Models\Usuarios\UserModel')->
getFullName($pedidoEntity->fecha_encuadernado_change_user_id):""; getFullName($pedidoEntity->fecha_encuadernado_change_user_id) : "";
$pedidoEntity->fecha_entrega_change_externo_user = $pedidoEntity->fecha_entrega_change_externo_user_id?model('App\Models\Usuarios\UserModel')-> $pedidoEntity->fecha_entrega_change_externo_user = $pedidoEntity->fecha_entrega_change_externo_user_id ? model('App\Models\Usuarios\UserModel')->
getFullName($pedidoEntity->fecha_entrega_change_externo_user_id):""; getFullName($pedidoEntity->fecha_entrega_change_externo_user_id) : "";
$this->viewData['pedidoEntity'] = $pedidoEntity; $this->viewData['pedidoEntity'] = $pedidoEntity;
if($pedidoEntity->estado == 'validacion'){ if ($pedidoEntity->estado == 'validacion') {
$clienteModel = model('App\Models\Clientes\ClienteModel'); $clienteModel = model('App\Models\Clientes\ClienteModel');
$pendiente = $clienteModel->getPendienteCobro($pedidoEntity->cliente_id); $pendiente = $clienteModel->getPendienteCobro($pedidoEntity->cliente_id);
$pendiente = $pendiente[0] + $pendiente[1]; $pendiente = $pendiente[0] + $pendiente[1];
@ -332,24 +334,25 @@ class Pedido extends \App\Controllers\BaseResourceController
$modelOrden = new \App\Models\OrdenTrabajo\OrdenTrabajoModel(); $modelOrden = new \App\Models\OrdenTrabajo\OrdenTrabajoModel();
$orden = $modelOrden->where('pedido_id', $pedidoEntity->id)->first(); $orden = $modelOrden->where('pedido_id', $pedidoEntity->id)->first();
if($orden){ if ($orden) {
$this->viewData['orden_id'] = $orden->id; $this->viewData['orden_id'] = $orden->id;
} }
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Pedidos.moduleTitle') . ' ' . lang('Basic.global.edit3'); $this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Pedidos.moduleTitle') . ' ' . lang('Basic.global.edit3');
return $this->displayForm(__METHOD__, $id); return $this->displayForm(__METHOD__, $id);
} }
public function datatable(){ public function datatable()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$reqData = $this->request->getPost(); $reqData = $this->request->getPost();
if (!isset($reqData['draw']) || !isset($reqData['columns']) ) { if (!isset($reqData['draw']) || !isset($reqData['columns'])) {
$errstr = 'No data available in response to this specific request.'; $errstr = 'No data available in response to this specific request.';
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr); $response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
return $response; return $response;
} }
$start = $reqData['start'] ?? 0; $start = $reqData['start'] ?? 0;
@ -360,7 +363,8 @@ class Pedido extends \App\Controllers\BaseResourceController
$dir = $reqData['order']['0']['dir'] ?? 'asc'; $dir = $reqData['order']['0']['dir'] ?? 'asc';
$estado = $reqData['estado'] ?? 'todos'; $estado = $reqData['estado'] ?? 'todos';
$cliente_id = $reqData['cliente_id'] ?? -1; $cliente_id = $reqData['cliente_id'] ?? -1;
if($estado == 'todos') $estado = ''; if ($estado == 'todos')
$estado = '';
$showTotal = $reqData['showTotal'] ?? false; $showTotal = $reqData['showTotal'] ?? false;
@ -373,7 +377,7 @@ class Pedido extends \App\Controllers\BaseResourceController
$extra_data['total_tirada'] = $totalTirada; $extra_data['total_tirada'] = $totalTirada;
$extra_data['total'] = $total; $extra_data['total'] = $total;
$total2 = 0; $total2 = 0;
if($showTotal){ if ($showTotal) {
$total2 = $model_linea->getTotalOfTotalAceptado($estado); $total2 = $model_linea->getTotalOfTotalAceptado($estado);
$tirada2 = $model_linea->getTotalTirada($estado); $tirada2 = $model_linea->getTotalTirada($estado);
$extra_data['total2'] = $total2; $extra_data['total2'] = $total2;
@ -422,11 +426,11 @@ class Pedido extends \App\Controllers\BaseResourceController
$result = DataTable::of($q) $result = DataTable::of($q)
->edit( ->edit(
'fecha', 'fecha',
fn($q) => $q->fecha?Time::createFromFormat("Y-m-d H:i:s", $q->fecha)->format("d/m/Y"):"" fn($q) => $q->fecha ? Time::createFromFormat("Y-m-d H:i:s", $q->fecha)->format("d/m/Y") : ""
) )
->edit( ->edit(
'fecha_entrega', 'fecha_entrega',
fn($q) => $q->fecha_entrega?Time::createFromFormat("Y-m-d H:i:s", $q->fecha_entrega)->format("d/m/Y"):"" fn($q) => $q->fecha_entrega ? Time::createFromFormat("Y-m-d H:i:s", $q->fecha_entrega)->format("d/m/Y") : ""
) )
->edit( ->edit(
"estado", "estado",
@ -453,13 +457,14 @@ class Pedido extends \App\Controllers\BaseResourceController
<a href="javascript:void(0);"><i class="ti ti-eye ti-sm btn-edit mx-2" data-id="' . $q->id . '"></i></a> <a href="javascript:void(0);"><i class="ti ti-eye ti-sm btn-edit mx-2" data-id="' . $q->id . '"></i></a>
</div> </div>
'; ';
}); });
return $result->toJson(returnAsObject: true) ; return $result->toJson(returnAsObject: true);
} }
public function obtenerTotalPedidosCliente($cliente_id){ public function obtenerTotalPedidosCliente($cliente_id)
{
$error = false; $error = false;
$result = [ $result = [
@ -472,37 +477,37 @@ class Pedido extends \App\Controllers\BaseResourceController
->join('pedidos_linea', 'pedidos_linea.pedido_id = pedidos.id') ->join('pedidos_linea', 'pedidos_linea.pedido_id = pedidos.id')
->join('presupuestos', 'presupuestos.id = pedidos_linea.presupuesto_id') ->join('presupuestos', 'presupuestos.id = pedidos_linea.presupuesto_id')
->groupBy('presupuestos.cliente_id')->get()->getResultObject(); ->groupBy('presupuestos.cliente_id')->get()->getResultObject();
if(count($data) > 0){ if (count($data) > 0) {
$result['total_impresion'] = round(floatval($data[0]->total), 2); $result['total_impresion'] = round(floatval($data[0]->total), 2);
} } else {
else{
$error = true; $error = true;
} }
$result['total'] = $result['total_impresion'] + $result['total_maquetacion']; $result['total'] = $result['total_impresion'] + $result['total_maquetacion'];
return $this->respond(['status' => $error?'error':'success', 'totales' => $result]); return $this->respond(['status' => $error ? 'error' : 'success', 'totales' => $result]);
} }
public function obtenerPedidosForFacturas(){ public function obtenerPedidosForFacturas()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$reqData = $this->request->getPost(); $reqData = $this->request->getPost();
$start = $reqData['start'] ?? 0; $start = $reqData['start'] ?? 0;
} } else {
else {
return $this->failUnauthorized('Invalid request', 403); return $this->failUnauthorized('Invalid request', 403);
} }
} }
public function getlineas(){ public function getlineas()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$reqData = $this->request->getPost(); $reqData = $this->request->getPost();
if (!isset($reqData['draw']) || !isset($reqData['columns']) ) { if (!isset($reqData['draw']) || !isset($reqData['columns'])) {
$errstr = 'No data available in response to this specific request.'; $errstr = 'No data available in response to this specific request.';
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr); $response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
return $response; return $response;
} }
$id = $reqData['pedido_id'] ?? 0; $id = $reqData['pedido_id'] ?? 0;
$resourceData = $this->model->obtenerLineasPedido($id); $resourceData = $this->model->obtenerLineasPedido($id);
@ -517,25 +522,26 @@ class Pedido extends \App\Controllers\BaseResourceController
} }
public function addFactura(){ public function addFactura()
{
if ($this->request->isAJAX()) {
if($this->request->isAJAX()){
$modelFactura = model('App\Models\Facturas\FacturaModel'); $modelFactura = model('App\Models\Facturas\FacturaModel');
$modelFacturaLinea = model('App\Models\Facturas\FacturaLineaModel'); $modelFacturaLinea = model('App\Models\Facturas\FacturaLineaModel');
$pedido_id = $this->request->getPost('pedido_id'); $pedido_id = $this->request->getPost('pedido_id');
$serie_id = $this->request->getPost('serie_id'); $serie_id = $this->request->getPost('serie_id');
$datosFactura = $this->model->obtenerDatosForFactura($pedido_id); $datosFactura = $this->model->obtenerDatosForFactura($pedido_id);
if(count($datosFactura) == 0){ if (count($datosFactura) == 0) {
return $this->respond(['status' => 'error', 'message' => 'Error obteniendo datos de factura']); return $this->respond(['status' => 'error', 'message' => 'Error obteniendo datos de factura']);
} }
$datosFactura = $datosFactura[0]; $datosFactura = $datosFactura[0];
$modelFactura->insert([ $modelFactura->insert([
'cliente_id' => $datosFactura->cliente_id, 'cliente_id' => $datosFactura->cliente_id,
'serie_id' => $serie_id, 'serie_id' => $serie_id,
@ -555,13 +561,13 @@ class Pedido extends \App\Controllers\BaseResourceController
$factura_id = $modelFactura->getInsertID(); $factura_id = $modelFactura->getInsertID();
if($factura_id){ if ($factura_id) {
$model_pedido_linea = model('\App\Models\Pedidos\PedidoLineaModel'); $model_pedido_linea = model('\App\Models\Pedidos\PedidoLineaModel');
$lineas = $model_pedido_linea->where('pedido_id', $pedido_id)->first(); $lineas = $model_pedido_linea->where('pedido_id', $pedido_id)->first();
$facturas = new Facturas(); $facturas = new Facturas();
$result = $facturas->addLineaPedidoImpresion($factura_id, $lineas->id); $result = $facturas->addLineaPedidoImpresion($factura_id, $lineas->id);
if($result['error'] == 0){ if ($result['error'] == 0) {
// Se actualiza el precio total de la factura obtenido de la linea añadida // Se actualiza el precio total de la factura obtenido de la linea añadida
$linea_added = $modelFacturaLinea->where('factura_id', $factura_id)->first(); $linea_added = $modelFacturaLinea->where('factura_id', $factura_id)->first();
$modelFactura->set([ $modelFactura->set([
@ -570,27 +576,28 @@ class Pedido extends \App\Controllers\BaseResourceController
'pendiente' => $linea_added->total, 'pendiente' => $linea_added->total,
])->where('id', $factura_id)->update(); ])->where('id', $factura_id)->update();
return $this->respond(['status' => 'success', 'id' => $factura_id, 'message' => lang('Basic.global.success')]); return $this->respond(['status' => 'success', 'id' => $factura_id, 'message' => lang('Basic.global.success')]);
}else{ } else {
return $this->respond(['status' => 'error', 'message' => 'Error insertando lineas de factura']); return $this->respond(['status' => 'error', 'message' => 'Error insertando lineas de factura']);
} }
} }
return $this->respond(['status' => 'error', 'message' => 'Error insertando factura']); return $this->respond(['status' => 'error', 'message' => 'Error insertando factura']);
}else{ } else {
return $this->failUnauthorized('Invalid request', 403); return $this->failUnauthorized('Invalid request', 403);
} }
} }
private function obtenerDatosFormulario(&$pedidoEntity){ private function obtenerDatosFormulario(&$pedidoEntity)
{
$datos = $this->model->obtenerDatosForm($pedidoEntity->id); $datos = $this->model->obtenerDatosForm($pedidoEntity->id);
$pedidoEntity->estadoText = lang('Pedidos.' . $pedidoEntity->estado); $pedidoEntity->estadoText = lang('Pedidos.' . $pedidoEntity->estado);
if(count($datos) > 0){ if (count($datos) > 0) {
$pedidoEntity->cliente = $datos[0]->cliente; $pedidoEntity->cliente = $datos[0]->cliente;
$pedidoEntity->cliente_id = $datos[0]->cliente_id; $pedidoEntity->cliente_id = $datos[0]->cliente_id;
$pedidoEntity->comercial = $datos[0]->comercial; $pedidoEntity->comercial = $datos[0]->comercial;
@ -602,8 +609,8 @@ class Pedido extends \App\Controllers\BaseResourceController
$pedidoEntity->fecha_entrega_externo_text = $pedidoEntity->fecha_entrega_externo ? date('d/m/Y', strtotime($pedidoEntity->fecha_entrega_externo)) : ''; $pedidoEntity->fecha_entrega_externo_text = $pedidoEntity->fecha_entrega_externo ? date('d/m/Y', strtotime($pedidoEntity->fecha_entrega_externo)) : '';
$userModel = model('App\Models\Usuarios\UserModel'); $userModel = model('App\Models\Usuarios\UserModel');
$pedidoEntity->created_by = $userModel->getFullName($pedidoEntity->user_created_id); $pedidoEntity->created_by = $userModel->getFullName($pedidoEntity->user_created_id);
$pedidoEntity->updated_by = $userModel->getFullName($pedidoEntity->user_updated_id); $pedidoEntity->updated_by = $userModel->getFullName($pedidoEntity->user_updated_id);
$pedidoEntity->created_at_footer = $pedidoEntity->created_at ? date(' H:i d/m/Y', strtotime($pedidoEntity->created_at)) : ''; $pedidoEntity->created_at_footer = $pedidoEntity->created_at ? date(' H:i d/m/Y', strtotime($pedidoEntity->created_at)) : '';
$pedidoEntity->updated_at_footer = $pedidoEntity->updated_at ? date(' H:i d/m/Y', strtotime($pedidoEntity->updated_at)) : ''; $pedidoEntity->updated_at_footer = $pedidoEntity->updated_at ? date(' H:i d/m/Y', strtotime($pedidoEntity->updated_at)) : '';
} }
@ -613,21 +620,36 @@ class Pedido extends \App\Controllers\BaseResourceController
// $xml_service = new PedidoXMLService($this->model); // $xml_service = new PedidoXMLService($this->model);
return $this->respond($data); return $this->respond($data);
} }
public function to_produccion($pedido_id) public function to_produccion($pedido_id)
{ {
$serviceProduction = service('production'); $serviceProduction = service('production');
$pedido = $this->model->find($pedido_id); $pedido = $this->model->find($pedido_id);
$cliente = $pedido->presupuesto()->cliente_id;
$serviceProduction->setPedido($pedido); $serviceProduction->setPedido($pedido);
if($pedido->orden_trabajo()){ if ($pedido->orden_trabajo()) {
return $this->response->setJSON(["status"=>false,"data"=>$pedido->orden_trabajo(),"message" => "Ya existe una orden de trabajo para este pedido"]); return $this->response->setJSON(["status" => false, "data" => $pedido->orden_trabajo(), "message" => "Ya existe una orden de trabajo para este pedido"]);
}else{ } else {
$r = $serviceProduction->createOrdenTrabajo(); $r = $serviceProduction->createOrdenTrabajo();
$this->model->set(['estado' => 'produccion'])->where('id', $pedido_id)->update(); $this->model->set(['estado' => 'produccion'])->where('id', $pedido_id)->update();
return $this->response->setJSON(["status"=>true, "data"=>$r,"message" => "Orden trabajo creada correctamente"]); $clienteModel = model('App\Models\Clientes\ClienteModel');
$cliente = $clienteModel->find($cliente);
if ($cliente) {
if ($cliente->tirada_flexible == 1) {
$ejemplares_tirada_flexible = intval($pedido->total_tirada * 0.05);
$comentario = lang('OrdenTrabajo.tiradaFlexible', [
'unidades' => $ejemplares_tirada_flexible
]) . "\n" . trim($cliente->comentarios_tirada_flexible);
$serviceProduction->init($r->id)->updateOrdenTrabajoData([
'name' => 'comment_logistica',
'comment_logistica' => $comentario
]);
}
}
return $this->response->setJSON(["status" => true, "data" => $r, "message" => "Orden trabajo creada correctamente"]);
} }
} }
} }

View File

@ -0,0 +1,6 @@
<?php
return [
'tiradaFlexible' => 'El cliente tiene opción de tirada flexible: ±{unidades, number, integer} unidades.',
];

View File

@ -253,7 +253,8 @@ class PresupuestoService extends BaseService
$linea['fields']['precio_libro'] = $linea['fields']['pliegos_libro'] * $linea['fields']['precios_pliegos']; $linea['fields']['precio_libro'] = $linea['fields']['pliegos_libro'] * $linea['fields']['precios_pliegos'];
// Precio papel pedido // Precio papel pedido
$linea['fields']['precio_pedido'] = $linea['fields']['precio_libro'] * ($datosPedido->tirada + $datosPedido->merma); $linea['fields']['precio_pedido'] = $linea['fields']['precio_libro'] * ($datosPedido->tirada + $datosPedido->merma);
$linea['fields']['margen_papel_pedido'] = $linea['fields']['pliegos_libro'] * $margen_pliego_impresion * ($datosPedido->tirada + $datosPedido->merma);; $linea['fields']['margen_papel_pedido'] = $linea['fields']['pliegos_libro'] * $margen_pliego_impresion * ($datosPedido->tirada + $datosPedido->merma);
;
$linea['fields']['a_favor_fibra'] = $parametrosRotativa->a_favor_fibra; $linea['fields']['a_favor_fibra'] = $parametrosRotativa->a_favor_fibra;
$linea['fields']['maquina'] = $maquina->maquina; $linea['fields']['maquina'] = $maquina->maquina;
@ -614,9 +615,9 @@ class PresupuestoService extends BaseService
// precio tinta // precio tinta
$data['precio_tinta'] = round( $data['precio_tinta'] = round(
round(($data['peso_gotas_negro_pedido'] / 1000.0) * $maquina->precio_tinta_negro, 2) + round(($data['peso_gotas_negro_pedido'] / 1000.0) * $maquina->precio_tinta_negro, 2) +
round(($data['peso_gotas_cyan_pedido'] / 1000.0) * $maquina->precio_tinta_color, 2) + round(($data['peso_gotas_cyan_pedido'] / 1000.0) * $maquina->precio_tinta_color, 2) +
round(($data['peso_gotas_magenta_pedido'] / 1000.0) * $maquina->precio_tinta_color, 2) + round(($data['peso_gotas_magenta_pedido'] / 1000.0) * $maquina->precio_tinta_color, 2) +
round(($data['peso_gotas_amarillo_pedido'] / 1000.0) * $maquina->precio_tinta_color, 2), round(($data['peso_gotas_amarillo_pedido'] / 1000.0) * $maquina->precio_tinta_color, 2),
2 2
); );
@ -1801,7 +1802,7 @@ class PresupuestoService extends BaseService
)->orderBy("t1.id", "asc")->get()->getResultObject(); )->orderBy("t1.id", "asc")->get()->getResultObject();
$query = model("App\Models\Configuracion\PapelImpresionModel")->db->getLastQuery(); $query = model("App\Models\Configuracion\PapelImpresionModel")->db->getLastQuery();
// Se recorren las máquinas y se calcula el coste de linea por cada una // Se recorren las máquinas y se calcula el coste de linea por cada una
foreach ($maquinas as $maquina) { foreach ($maquinas as $maquina) {
@ -1867,7 +1868,7 @@ class PresupuestoService extends BaseService
public static function crearPedido($presupuesto_id,?bool $isImported = false) public static function crearPedido($presupuesto_id, ?bool $isImported = false)
{ {
$model_pedido = model('App\Models\Pedidos\PedidoModel'); $model_pedido = model('App\Models\Pedidos\PedidoModel');
$model_pedido_linea = model('App\Models\Pedidos\PedidoLineaModel'); $model_pedido_linea = model('App\Models\Pedidos\PedidoLineaModel');
@ -1913,6 +1914,23 @@ class PresupuestoService extends BaseService
$r = $serviceProduction->createOrdenTrabajo($isImported); $r = $serviceProduction->createOrdenTrabajo($isImported);
$modelPedido->set(['estado' => 'produccion'])->where('id', $pedido_id)->update(); $modelPedido->set(['estado' => 'produccion'])->where('id', $pedido_id)->update();
$clienteModel = model('App\Models\Clientes\ClienteModel');
$cliente = $clienteModel->find($datos_presupuesto->cliente_id);
$clienteModel = model('App\Models\Clientes\ClienteModel');
if ($cliente) {
if ($cliente->tirada_flexible == 1) {
$ejemplares_tirada_flexible = intval($datos_presupuesto->tirada * 0.05);
$comentario = lang('OrdenTrabajo.tiradaFlexible', [
'unidades' => $ejemplares_tirada_flexible
]) . "\n" . trim($cliente->comentarios_tirada_flexible);
$serviceProduction->init($r->id)->updateOrdenTrabajoData([
'name' => 'comment_logistica',
'comment_logistica' => $comentario
]);
}
}
} }
} }
return true; return true;

View File

@ -1157,6 +1157,16 @@ class ProductionService extends BaseService
$this->updateProgress(); $this->updateProgress();
return $result; return $result;
} }
public function updateOrdenTrabajoData($data)
{
$result = $this->otModel->where('id', $this->ot->id)
->set($data['name'], $data[$data['name']])
->update();
return $result;
}
public function emptyOrdenTrabajoDate(int $orden_trabajo_id, string $dateName) public function emptyOrdenTrabajoDate(int $orden_trabajo_id, string $dateName)
{ {
$status = $this->otDate->where('orden_trabajo_id', $orden_trabajo_id) $status = $this->otDate->where('orden_trabajo_id', $orden_trabajo_id)