Skip to content

Commit

Permalink
Refactoring module log4net
Browse files Browse the repository at this point in the history
  • Loading branch information
rudi-krsoftware committed Jan 24, 2017
1 parent e829451 commit deb933a
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 56 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ Prerequisites
* [Dapper.Contrib](http://www.nuget.org/packages/Dapper.Contrib/)
* [Npgsql 2.2.7](http://www.nuget.org/packages/Npgsql/2.2.72)
* [Apache log4net](https://www.nuget.org/packages/log4net/)
* [Json.NET](http://www.nuget.org/packages/Newtonsoft.Json/9.0.1)
* [CrashReporter.NET](http://www.nuget.org/packages/CrashReporter.NET.Official/)
* [AutoUpdater.NET](https://www.nuget.org/packages/Autoupdater.NET.Official/)
* [DockPanel Suite](https://www.nuget.org/packages/DockPanelSuite/)
* [DockPanel Suite VS2013 Blue Theme](https://www.nuget.org/packages/DockPanelSuite.ThemeVS2013Blue/)
* [Syncfusion Community Edition](https://www.syncfusion.com/products/communitylicense/) versi 13.3.0.12
* [Crystal Reports .NET](http://downloads.businessobjects.com/akdlm/cr4vs2010/CRforVS_13_0_15.exe) versi 13.0.15

Expand Down
123 changes: 81 additions & 42 deletions database/DbOpenRetail.sql
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ DECLARE
var_total_nota t_harga;
var_jumlah_retur_lama t_jumlah;
var_jumlah_retur_baru t_jumlah;
var_tahun_tempo INTEGER;
var_tanggal_tempo DATE;
is_retur t_bool;
BEGIN
Expand Down Expand Up @@ -752,13 +752,9 @@ BEGIN
is_retur := TRUE;
var_retur_beli_id := (SELECT retur_beli_produk_id FROM t_retur_beli_produk WHERE beli_produk_id = var_beli_produk_id LIMIT 1);
var_tahun_tempo := (SELECT EXTRACT(YEAR FROM tanggal_tempo) FROM t_beli_produk WHERE beli_produk_id = var_beli_produk_id);
var_tanggal_tempo := (SELECT tanggal_tempo FROM t_beli_produk WHERE beli_produk_id = var_beli_produk_id);
IF var_tahun_tempo IS NULL THEN
var_tahun_tempo := 0;
END IF;
IF var_tahun_tempo < 2010 THEN -- nota tunai
IF var_tanggal_tempo IS NULL THEN -- nota tunai
UPDATE t_beli_produk SET total_nota = var_total_nota, retur_beli_produk_id = var_retur_beli_id
WHERE beli_produk_id = var_beli_produk_id;
Expand Down Expand Up @@ -808,7 +804,8 @@ BEGIN
-- hitung total hutang dan pelunasan pembelian produk
SELECT SUM(total_nota - diskon + ppn) AS total_hutang, SUM(total_pelunasan) AS total_pelunasan
INTO var_total_hutang_produk, var_total_pelunasan_produk
FROM t_beli_produk WHERE EXTRACT(YEAR FROM tanggal_tempo) > 2010 AND supplier_id = var_supplier_id;
FROM t_beli_produk
WHERE tanggal_tempo IS NOT NULL AND supplier_id = var_supplier_id;
IF var_total_hutang_produk IS NULL THEN
var_total_hutang_produk := 0;
Expand All @@ -828,7 +825,8 @@ BEGIN
-- hitung total hutang dan pelunasan pembelian produk
SELECT SUM(total_nota - diskon + ppn) AS total_hutang, SUM(total_pelunasan) AS total_pelunasan
INTO var_total_hutang_produk, var_total_pelunasan_produk
FROM t_beli_produk WHERE EXTRACT(YEAR FROM tanggal_tempo) > 2010 AND supplier_id = var_supplier_id_old;
FROM t_beli_produk
WHERE tanggal_tempo IS NOT NULL AND supplier_id = var_supplier_id_old;
IF var_total_hutang_produk IS NULL THEN
var_total_hutang_produk := 0;
Expand Down Expand Up @@ -867,7 +865,7 @@ DECLARE
var_total_nota t_harga;
var_jumlah_retur_lama t_jumlah;
var_jumlah_retur_baru t_jumlah;
var_tahun_tempo INTEGER;
var_tanggal_tempo DATE;
is_retur t_bool;
BEGIN
Expand Down Expand Up @@ -898,13 +896,9 @@ BEGIN
is_retur := TRUE;
var_retur_jual_id := (SELECT retur_jual_id FROM t_retur_jual_produk WHERE jual_id = var_jual_id LIMIT 1);
var_tahun_tempo := (SELECT EXTRACT(YEAR FROM tanggal_tempo) FROM t_jual_produk WHERE jual_id = var_jual_id);
IF var_tahun_tempo IS NULL THEN
var_tahun_tempo := 0;
END IF;
var_tanggal_tempo := (SELECT tanggal_tempo FROM t_jual_produk WHERE jual_id = var_jual_id);
IF var_tahun_tempo < 2010 THEN -- nota tunai
IF var_tanggal_tempo IS NULL THEN -- nota tunai
UPDATE t_jual_produk SET total_nota = var_total_nota, retur_jual_id = var_retur_jual_id
WHERE jual_id = var_jual_id;
Expand Down Expand Up @@ -1024,9 +1018,10 @@ BEGIN
var_customer_id_old = OLD.customer_id;
END IF;
SELECT SUM(total_nota - diskon + transport + ppn), SUM(total_pelunasan)
SELECT SUM(total_nota - diskon + ppn), SUM(total_pelunasan)
INTO var_total_piutang, var_total_pelunasan
FROM t_jual_produk WHERE EXTRACT(YEAR FROM tanggal_tempo) > 2010 AND customer_id = var_customer_id;
FROM t_jual_produk
WHERE tanggal_tempo IS NOT NULL AND customer_id = var_customer_id;
IF var_total_piutang IS NULL THEN
var_total_piutang := 0;
Expand All @@ -1043,9 +1038,10 @@ BEGIN
var_customer_id_old = OLD.customer_id;
IF var_customer_id <> var_customer_id_old THEN
SELECT SUM(total_nota - diskon + transport + ppn), SUM(total_pelunasan)
SELECT SUM(total_nota - diskon + ppn), SUM(total_pelunasan)
INTO var_total_piutang, var_total_pelunasan
FROM t_jual_produk WHERE EXTRACT(YEAR FROM tanggal_tempo) > 2010 AND customer_id = var_customer_id_old;
FROM t_jual_produk
WHERE tanggal_tempo IS NOT NULL AND customer_id = var_customer_id_old;
IF var_total_piutang IS NULL THEN
var_total_piutang := 0;
Expand All @@ -1059,7 +1055,7 @@ BEGIN
WHERE customer_id = var_customer_id_old;
UPDATE t_pembayaran_piutang_produk SET customer_id = var_customer_id
WHERE pembayaran_piutang_id IN (SELECT pembayaran_piutang_id FROM t_item_pembayaran_piutang WHERE jual_id = NEW.jual_id);
WHERE pembayaran_piutang_id IN (SELECT pembayaran_piutang_id FROM t_item_pembayaran_piutang_produk WHERE jual_id = NEW.jual_id);
END IF;
END IF;
Expand Down Expand Up @@ -1699,45 +1695,39 @@ CREATE TABLE t_jual_produk (
ALTER TABLE t_jual_produk OWNER TO postgres;

--
-- Name: t_jual_produk_jual_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
-- Name: t_jual_produk_jual_produk_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE t_jual_produk_jual_id_seq
CREATE SEQUENCE t_jual_produk_jual_produk_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;


ALTER TABLE t_jual_produk_jual_id_seq OWNER TO postgres;
ALTER TABLE t_jual_produk_jual_produk_id_seq OWNER TO postgres;

--
-- Name: t_logs; Type: TABLE; Schema: public; Owner: postgres; Tablespace:
--

CREATE TABLE t_logs (
log_id bigint DEFAULT nextval(('public.t_logs_log_id_seq'::text)::regclass) NOT NULL,
app_name text,
thread character varying(255),
level character varying(10),
location text,
message text,
exception text,
log_date timestamp without time zone DEFAULT now(),
created_by character varying(50)
class_name character varying(200),
method_name character varying(100),
message character varying(100),
new_value character varying(1000),
old_value character varying(1000),
exception character varying(5000),
created_by character varying(50),
log_date timestamp(0) without time zone DEFAULT now()
);


ALTER TABLE t_logs OWNER TO postgres;

--
-- Name: COLUMN t_logs.created_by; Type: COMMENT; Schema: public; Owner: postgres
--

COMMENT ON COLUMN t_logs.created_by IS 'nama operator';


--
-- Name: t_logs_log_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--
Expand Down Expand Up @@ -2293,25 +2283,74 @@ ALTER TABLE ONLY t_retur_jual_produk
ADD CONSTRAINT t_retur_jual_pkey PRIMARY KEY (retur_jual_id);


--
-- Name: m_customer_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace:
--

CREATE INDEX m_customer_idx ON m_customer USING btree (nama_customer);


--
-- Name: m_produk_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace:
--

CREATE INDEX m_produk_idx ON m_produk USING btree (nama_produk, kode_produk);
CREATE INDEX m_produk_idx ON m_produk USING btree (nama_produk);


--
-- Name: m_produk_idx1; Type: INDEX; Schema: public; Owner: postgres; Tablespace:
--

CREATE INDEX m_produk_idx1 ON m_produk USING btree (kode_produk);


--
-- Name: m_supplier_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace:
--

CREATE INDEX m_supplier_idx ON m_supplier USING btree (nama_supplier);


--
-- Name: t_beli_produk_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace:
--

CREATE INDEX t_beli_produk_idx ON t_beli_produk USING btree (supplier_id, tanggal);
CREATE INDEX t_beli_produk_idx ON t_beli_produk USING btree (tanggal);


--
-- Name: t_beli_produk_idx1; Type: INDEX; Schema: public; Owner: postgres; Tablespace:
--

CREATE INDEX t_beli_produk_idx1 ON t_beli_produk USING btree (nota);


--
-- Name: t_gaji_karyawan_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace:
--

CREATE INDEX t_gaji_karyawan_idx ON t_gaji_karyawan USING btree (bulan, tahun);


--
-- Name: t_gaji_karyawan_idx1; Type: INDEX; Schema: public; Owner: postgres; Tablespace:
--

CREATE INDEX t_gaji_karyawan_idx1 ON t_gaji_karyawan USING btree (tanggal);


--
-- Name: t_jual_produk_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace:
--

CREATE INDEX t_jual_produk_idx ON t_jual_produk USING btree (nota);


--
-- Name: t_jual_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace:
-- Name: t_jual_produk_idx1; Type: INDEX; Schema: public; Owner: postgres; Tablespace:
--

CREATE INDEX t_jual_idx ON t_jual_produk USING btree (pengguna_id, tanggal);
CREATE INDEX t_jual_produk_idx1 ON t_jual_produk USING btree (tanggal);


--
Expand Down
5 changes: 2 additions & 3 deletions src/OpenRetail.App/MainProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static class MainProgram
/// <summary>
/// Instance log4net
/// </summary>
public static readonly ILog log = LogManager.GetLogger(typeof(MainProgram));
public static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

public static readonly string appName = "Open Retail Versi {0} - Copyright © 2017 Kamarudin";

Expand All @@ -50,8 +50,7 @@ static class MainProgram
[STAThread]
static void Main()
{
log4net.GlobalContext.Properties["AppName"] = Assembly.GetExecutingAssembly().FullName;
log4net.GlobalContext.Properties["Operator"] = "Kamarudin"; // TODO: fix me (ganti dengan user yang login)
log4net.GlobalContext.Properties["UserName"] = "Admin"; // TODO: fix me (ganti dengan user yang login)

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Expand Down
9 changes: 5 additions & 4 deletions src/OpenRetail.Model/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ namespace OpenRetail.Model
[Table("t_logs")]
public class Log
{
public string app_name { get; set; }
public string thread { get; set; }
public string level { get; set; }
public string location { get; set; }
public string class_name { get; set; }
public string method_name { get; set; }
public string message { get; set; }
public string new_value { get; set; }
public string old_value { get; set; }
public string exception { get; set; }
public string created_by { get; set; }
public string created_by { get; set; }
}
}
13 changes: 13 additions & 0 deletions src/OpenRetail.Model/ModelExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Newtonsoft.Json;
using Dapper.Contrib.Extensions;

namespace OpenRetail.Model
Expand Down Expand Up @@ -66,5 +68,16 @@ public static bool IsNull(this Nullable<DateTime> tanggal)

return result;
}

/// <summary>
/// Method untuk mengkonversi nilai object ke format json
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="obj"></param>
/// <returns></returns>
public static string ToJson<T>(this T obj)
{
return JsonConvert.SerializeObject(obj);
}
}
}
4 changes: 4 additions & 0 deletions src/OpenRetail.Model/OpenRetail.Model.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
<HintPath>..\..\lib\FluentValidation.6.2.1.0\lib\portable-net40+sl50+wp80+win8+wpa81\FluentValidation.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\lib\Newtonsoft.Json.9.0.1\lib\net40\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
Expand Down
1 change: 1 addition & 0 deletions src/OpenRetail.Model/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<package id="Dapper" version="1.50.2" targetFramework="net40" />
<package id="Dapper.Contrib" version="1.50.0" targetFramework="net40" />
<package id="FluentValidation" version="6.2.1.0" targetFramework="net40" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net40" />
</packages>
18 changes: 12 additions & 6 deletions src/OpenRetail.Repository.Service/Log4NetRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Linq;
using System.Text;

using log4net;
using log4net.Core;
using log4net.Appender;

Expand Down Expand Up @@ -75,22 +76,27 @@ public class Log4NetAppender : AppenderSkeleton
{
protected override void Append(LoggingEvent loggingEvent)
{
var appName = (loggingEvent.LookupProperty("AppName") != null) ? loggingEvent.LookupProperty("AppName").ToString() : string.Empty;
var createdBy = (loggingEvent.LookupProperty("Operator") != null) ? loggingEvent.LookupProperty("Operator").ToString() : string.Empty;
// cek nilai custom properties
var newValue = (loggingEvent.LookupProperty("NewValue") != null) ? loggingEvent.LookupProperty("NewValue").ToString() : string.Empty;
var oldValue = (loggingEvent.LookupProperty("OldValue") != null) ? loggingEvent.LookupProperty("OldValue").ToString() : string.Empty;
var createdBy = (loggingEvent.LookupProperty("UserName") != null) ? loggingEvent.LookupProperty("UserName").ToString() : string.Empty;

var log = new Log
{
app_name = appName,
thread = loggingEvent.ThreadName,
level = loggingEvent.Level.ToString(),
location = loggingEvent.LocationInformation.FullInfo,
class_name = loggingEvent.LocationInformation.ClassName,
method_name = loggingEvent.LocationInformation.MethodName,
message = loggingEvent.RenderedMessage,
new_value = newValue,
old_value = oldValue,
exception = loggingEvent.GetExceptionString(),
created_by = createdBy
};

var result = 0;
// reset nilai property NewValue dan OldValue
LogicalThreadContext.Properties.Clear();

var result = 0;
using (IDapperContext context = new DapperContext())
{
IUnitOfWork uow = new UnitOfWork(context, null);
Expand Down

0 comments on commit deb933a

Please sign in to comment.