79 lines
3.6 KiB
C#
79 lines
3.6 KiB
C#
using Net.Business.Entities.WMS.Transferencia;
|
|
using Sap.Data.Hana;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
|
|
namespace Net.Data.HelperData.Invoices
|
|
{
|
|
public class HelperInvoice
|
|
{
|
|
public static int Get(string DocNum)
|
|
{
|
|
DataTable dt = new DataTable();
|
|
int DocEntry = 0;
|
|
using (HanaConnection con = new HanaConnection(LocalData.ConnectionString))
|
|
{
|
|
con.Open();
|
|
HanaCommand cmd = new HanaCommand($"CALL\"{LocalData.Schema}\".\"ITCA_WMS_SAP_GetEntradaPorImportacion\"(?)", con);
|
|
cmd.Parameters.Add("DocNum", HanaDbType.VarChar).Value = DocNum ?? "";
|
|
HanaDataAdapter da = new HanaDataAdapter(cmd);
|
|
if (da != null)
|
|
{
|
|
da.Fill(dt);
|
|
}
|
|
con.Close();
|
|
}
|
|
|
|
for (int x = 0; x < dt.Rows.Count; x++)
|
|
{
|
|
DocEntry = (dt.Rows[x]["DocEntry"] != DBNull.Value) ? Convert.ToInt32(dt.Rows[x]["DocEntry"]) : 0;
|
|
}
|
|
|
|
return DocEntry;
|
|
}
|
|
|
|
// Lineas de todas las Entradas de Mercaderia (no anuladas) enlazadas (BaseType 18) a la Factura de Reserva
|
|
// de proveedores con ese DocNum (isIns = 'Y'). Si una linea ya tiene transferencia de stock (TargetType 67)
|
|
// y esa transferencia no esta anulada, TransferenciaDocEntry trae su DocEntry; si no, 0.
|
|
public static List<BE_EntradaImportacionLinea> GetEntradasPorFactura(string DocNum)
|
|
{
|
|
var lista = new List<BE_EntradaImportacionLinea>();
|
|
DataTable dt = new DataTable();
|
|
string esquema = LocalData.Schema;
|
|
using (HanaConnection con = new HanaConnection(LocalData.ConnectionString))
|
|
{
|
|
con.Open();
|
|
HanaCommand cmd = new HanaCommand(
|
|
$"SELECT E.\"DocEntry\", E.\"DocNum\", L.\"LineNum\", L.\"ItemCode\", L.\"Quantity\", " +
|
|
$"CASE WHEN L.\"TargetType\" = 67 AND W.\"DocEntry\" IS NOT NULL AND W.\"CANCELED\" = 'N' THEN W.\"DocEntry\" ELSE 0 END AS \"TransferenciaDocEntry\" " +
|
|
$"FROM \"{esquema}\".\"OPCH\" F " +
|
|
$"INNER JOIN \"{esquema}\".\"PDN1\" L ON L.\"BaseType\" = 18 AND L.\"BaseEntry\" = F.\"DocEntry\" " +
|
|
$"INNER JOIN \"{esquema}\".\"OPDN\" E ON E.\"DocEntry\" = L.\"DocEntry\" " +
|
|
$"LEFT JOIN \"{esquema}\".\"OWTR\" W ON L.\"TargetType\" = 67 AND W.\"DocEntry\" = L.\"TrgetEntry\" " +
|
|
$"WHERE F.\"DocNum\" = ? AND F.\"isIns\" = 'Y' AND E.\"CANCELED\" = 'N' " +
|
|
$"ORDER BY E.\"DocEntry\", L.\"LineNum\"", con);
|
|
cmd.Parameters.Add("DocNum", HanaDbType.VarChar).Value = DocNum ?? "";
|
|
HanaDataAdapter da = new HanaDataAdapter(cmd);
|
|
da.Fill(dt);
|
|
con.Close();
|
|
}
|
|
|
|
for (int x = 0; x < dt.Rows.Count; x++)
|
|
{
|
|
lista.Add(new BE_EntradaImportacionLinea()
|
|
{
|
|
DocEntry = Convert.ToInt32(dt.Rows[x]["DocEntry"]),
|
|
DocNum = Convert.ToInt32(dt.Rows[x]["DocNum"]),
|
|
LineNum = Convert.ToInt32(dt.Rows[x]["LineNum"]),
|
|
ItemCode = Convert.ToString(dt.Rows[x]["ItemCode"]),
|
|
Quantity = Convert.ToDecimal(dt.Rows[x]["Quantity"]),
|
|
TransferenciaDocEntry = Convert.ToInt32(dt.Rows[x]["TransferenciaDocEntry"]),
|
|
});
|
|
}
|
|
|
|
return lista;
|
|
}
|
|
}
|
|
}
|